菜单中的操作项设置文本颜色

action item in menu set text color

我有一个菜单,它在 3 个不同的活动中膨胀到工具栏上。其中一项活动有一个溢出菜单,在溢出菜单后面有一个操作。 我可以更改操作的背景颜色。我无法更改与操作关联的文本的文本颜色。请不要对我看过并尝试过所有 136 个类似的已发布问题投反对票。 下面是样式代码和菜单代码。

<resources>
<!-- Base application theme. -->
<!-- parent="Theme.AppCompat.NoActionBar"> -->
<!-- Line of CODE ABOVE gives WHITE color to items in ToolBar -->
<!-- Line of CODE BELOW gives BLACk color to items in ToolBar -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:itemBackground">@color/color_Red</item>
    <item name="actionMenuTextColor">@style/MyActionBarTitleText</item>
</style>

<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/color_Yellow</item>
</style>

菜单代码

<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  tools:context=".MainActivity">

<item
    android:id="@+id/action_ReSetPW"
    android:orderInCategory="100"
    android:title="@string/action_settings"
    app:showAsAction="never"
    android:visible="true"/>

附带说明一下,我也无法根据某些参数更改标题文本颜色。我想知道如何设置或更改文本颜色? 经过一些尝试和错误后,我发布了一个样式代码,其中包含以下解决方案解决方案代码的评论

<resources>
<!-- Base application theme. -->
<!-- parent="Theme.AppCompat.NoActionBar"> -->
<!-- Line of CODE ABOVE gives WHITE color to items in ToolBar -->
<!-- Line of CODE BELOW gives BLACk color to items in ToolBar -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:itemBackground">@color/color_Red</item>
    <!--The line of CODE above styles the action background color  -->

</style>

<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">21sp</item>
    <item name="android:textStyle">italic</item>
</style>

<!--ADD THIS TO THE XML that defines the widget ToolBar android:theme="@style/ToolbarTheme" -->
<!--the line of CODE above tells the ToolBar where to find the style to use -->
<!--Code below will make the Overflow three dots Yellow and the text of the Action Yellow -->
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/color_Yellow</item>
</style>

似乎部分解决方案是从 toolbar.xml

中调用样式

编辑:

This 答案有效:

styles.xml:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:itemTextAppearance">@style/itemTextStyle.AppTheme</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="itemTextStyle.AppTheme" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
    <item name="android:textColor">@color/color_item_popup</item>
</style>

res/color/color_item_popup.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#FFFF00"/>
    <item android:state_focused="true" android:color="#FFFF00"/>
    <item android:color="#00FFFF"/>
</selector>

你们都有正确的想法我建议你们看看这个 ThemeOverlay link 它解释了 ThemeOverlay vrs 主题。值得你花时间 James_Duh

ThemeOverlay

怎么会有人知道 TEXT textColorPrimary 引用的是什么。 我猜这一切都在 NAME

<item name="android:textColorPrimary">@color/color_White</item>
app:itemTextColor="@color/your_color"

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view_search"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/drawer_menu"
    app:itemTextColor="@color/colorWhite"
    app:itemIconTint="@android:color/white"
    android:background="@drawable/nav_drawer_background" />