Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Menu Text Color Change

Tags:

android

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>

like image 440
Bharat Kumar Avatar asked Dec 02 '22 12:12

Bharat Kumar


2 Answers

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);
}
like image 78
AskNilesh Avatar answered Dec 05 '22 01:12

AskNilesh


One simple line in your theme :)

<item name="android:actionMenuTextColor">@color/your_color</item>
like image 34
TheSwiftGuy77 Avatar answered Dec 05 '22 00:12

TheSwiftGuy77