4
votes

I am trying Material theme and changing the background and text color of Menu and items. Using the below style it works fine on the Toolbar, but the menu pop up while pressing device menu button shows no change in text color though the background got changed. Please help to change the text color as mentioned. enter image description here

<resources>

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">

</style>

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/accent</item>
    <item name="android:textColorSecondary">@color/accent</item>
    <item name="android:textColorHint">@color/accent</item>

    <!-- Menu Items -->
    <item name="android:textColor">@color/accent</item>
    <item name="android:actionMenuTextColor">@color/accent</item>
    <item name="actionMenuTextColor">@color/accent</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="android:itemBackground">@color/colorPrimaryDark</item>
    <item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>

    <!-- Menu Items -->
</style>



<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="background">@color/colorPrimaryDark</item>
    <item name="titleTextStyle">@style/MyActionBarTitle</item>
    <item name="actionMenuTextColor">@color/accent</item>

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

</style>
<style name="MyActionBar.MenuTextStyle">
    <item name="android:textColor">@color/accent</item>
    <item name="android:textStyle">bold</item>
    <item name="android:actionMenuTextColor">@color/accent</item>
    <item name="actionMenuTextColor">@color/accent</item>
</style>

5
If any of given answers solved your question, please accept it for future user reference.Abhi

5 Answers

9
votes

try this create this theme

<style name="TextAppearance" parent="@style/Theme.Sherlock.Light">
   <item name="actionMenuTextColor">@color/white</item>
   <item name="android:actionMenuTextColor">@color/white</item>
</style>

than apply this theme in your Activity theme like this

<style name="your_theme" parent="your_parent">
  <item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>

or try this

 @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.your_menu, menu);

    int positionOfMenuItem = 0; 
    MenuItem item = menu.getItem(positionOfMenuItem);
    SpannableString s = new SpannableString("My red MenuItem");
    s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
    item.setTitle(s);
}
7
votes

One simple line in your theme :)

<item name="android:actionMenuTextColor">@color/your_color</item>
0
votes

You can change the color of the overflow menu background by adding a new style in style.xml.

<style name="OverflowMenu"
parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/MyOverflowMenu</item>
<item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>
<style name="MyOverflowMenu" 
parent="@android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">@color/your_color</item> 
</style>
<style name="TextAppearance">
<item name="android:textColor">@color/your_color</item>
</style>
0
votes

Add one simple line in your theme .I hope this will solve your problem.

  <item name="android:textColor">@color/button_color</item>

enjoy..

0
votes
 // note if you want to style popup menu in toolbar    
 step 1-- Add your theme in toolbar 

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/MyPopupTheme" />

    step 2-- add style in styles.xml

    <style name="MyPopupTheme" parent="ThemeOverlay.AppCompat.Dark">
        <item name="android:colorControlActivated">@color/red </item>
        <item name="android:colorControlHighlight">@color/red</item>
        <item name="android:colorControlNormal">@color/yellow</item>
        <item name="android:textColorPrimary">@color/yellow</item>
    </style>


// note if you want to style menu text color  in toolbar itself
     <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/Mytoolbartheme"/    /> 


    <style name="Mytoolbartheme" parent="Theme.AppCompat.Light.DarkActionBar">

        <item name="actionMenuTextColor">@color/text_color</item>

    </style>

    // if you use android x then toolbar is
       <androidx.appcompat.widget.Toolbar
                android:layout_width="match_parent"
                android:id="@+id/toolbar"
                app:titleTextColor="@color/white"

                app:popupTheme="@style/MyPopupTheme"
                android:background="@color/colorsplash"
                android:layout_height="wrap_content">

        </androidx.appcompat.widget.Toolbar>