Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change title text and buttons color WITHOUT changing action overflow menu text color in new Toolbar?

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

Default Toolbar look likeenter image description here

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: enter image description here

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: enter image description here

So how can I change color for everything in the toolbar, except items in action overflow menu?

like image 686
udenfox Avatar asked Jan 30 '15 19:01

udenfox


People also ask

How can I change action bar title color?

xml file: Just go to res/values/styles. xml file. edit the xml file to change the color of action bar.

How do I change the color of the menu text?

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.

How do you change the color of the title bar on Android?

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?

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.


1 Answers

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.

like image 167
Willis Avatar answered Oct 24 '22 18:10

Willis