I use android.support.v7.widget.Toolbar in my project. By default in light theme it has black action overflow menu icon, black title and black overflow menu text color, like that (don't look at the navigation icon - it's custom):
But in my App I need it to be white. I set android:textColorPrimary to white in my styles for the toolbar:
<style name="Widget.My.Toolbar" parent="Widget.AppCompat.Toolbar">
<item name="theme">@style/ThemeOverlay.My.Toolbar</item>
</style>
<style name="ThemeOverlay.My.Toolbar" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/white</item>
</style>
It changed color of the title and the overflow menu button just like I wanted, but it changed Action owerflow menu items text color too:
It looks ugly. I even tried set a Title color programmatically with
toolbar.setTitleTextColor(getResources.getColor(R.color.white);
but it changes ONLY Title color, and not changes menu button:
So how can I change color for everything in the toolbar, except items in action overflow menu?
xml file: Just go to res/values/styles. xml file. edit the xml file to change the color of action bar.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 4 – Right-click on res, select New -> Android Resource Directory – menu.
In method 1 Just go to the activity_main. xml file and add a TextView in the toolbar widget with the text color attribute. The complete code for the activity_main.
Which attribute is used to set the color of the icon of the overflow menu? This can be achieved by setting the android:textColorSecondary theme attribute.
After you set the text color for for your Toolbar
you can set the text color of your menus with the following attribute:
<item name="actionMenuTextColor">@color/white</item>
Since you are using the AppCompat Toolbar
the android namespace need not be included in the attribute, as shown above.
However, it seems people have had mixed experience with this. You can also try using the itemTextAppearance
attribute:
<style name="yourTheme" parent="yourThemeParent">
<!-- Rest of your theme -->
<item name="android:itemTextAppearance">@style/menuItemColor</item>
</style>
<style name="menuItemColor">
<item name="android:textColor">@android:color/black</item>
</style>
I found that the first solution worked for me when I explicitly included a Toolbar
in my layout, but not if I used getSupportActionBar()
to get the default bar included in a given theme. However, in this scenario, the second solution did work for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With