0

I have a menu that is inflated on to a toolbar in 3 different Activities. One of the Activities has a Overflow menu with one Action behind the Overflow. I can change the background color of the Action. I can not change the text color of the text associated with the Action. Please do not down vote I have looked at and tried all 136 similar posted questions. Here is the styles code and menu code below.

<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 Code

<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"/>

As a side note I also could not change the Title Text Color based on some parameter. I would like to know how to set or change the text color? After some trial and ERROR I am posting a styles code with comments for a solution solution code below

<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>

It seems part of the solution is to call the style from the toolbar.xml

James_Duh
  • 1,321
  • 11
  • 31

3 Answers3

2

Edit:

This answer is working:

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>
Community
  • 1
  • 1
aschattney
  • 329
  • 4
  • 6
  • I tried that with no luck ! What has me confused is that the background color is set by direct in the base style any other thoughts? – James_Duh Oct 31 '16 at 23:19
  • try this answer: http://stackoverflow.com/questions/24652964/android-popup-menu-text-color-appcompat#answer-28818974 seems legit! – aschattney Oct 31 '16 at 23:26
  • well then replace `@color/color_item_popup` with your preferred color and you don't need that extra xml file in your case. – aschattney Oct 31 '16 at 23:57
  • I used part of your code it is quite extensive and I should have looked at it closer the first time I saw it. See my EDIT it works but I have not figured out all the ins and outs of it. What I was missing was the one line that goes in the ToolBar.XML thanks – James_Duh Nov 01 '16 at 00:35
1

You both have the correct idea I might suggest that you take a look at this ThemeOverlay link it explains the ThemeOverlay vrs Theme. Worth your time James_Duh

ThemeOverlay

How would anyone know what TEXT textColorPrimary was making reference to. I guess it is all in the NAME

<item name="android:textColorPrimary">@color/color_White</item>
Community
  • 1
  • 1
Vector
  • 3,066
  • 5
  • 27
  • 54
  • The link explains a lot esp the naming I used this line of code and now only the TEXT is set to the color I want and the Overflow remains consistent with the other Activities – James_Duh Nov 01 '16 at 03:20
0
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" />
  • While this code may answer the question, providing additional [context](https://meta.stackexchange.com/q/114762) regarding _how_ and/or _why_ it solves the problem would improve the answer's long-term value. Remember that you are answering the question for readers in the future, not just the person asking now! Please [edit](http://stackoverflow.com/posts/43165874/edit) your answer to add an explanation, and give an indication of what limitations and assumptions apply. It also doesn't hurt to mention why this answer is more appropriate than others. – Dev-iL Apr 02 '17 at 14:04