how can I change the text color of the ActionBar? I've inherited the Holo Light Theme, I'm able to change the background of the ActionBar but I don't find out what is the attribute to tweak to change the text color.
Ok, I'm able to change the text color with the attribute android:textColorPrimary but it also changes the text color of the dropdown menu displayed when an overflow happen on the ActionBar buttons. Any idea how to change the color of those dropdown menu / List ?
The ActionBar ID is not available directly, so you have to do little bit of hacking here.
A lot of answers are deprecated so I'll update the thread and show how to change text color and backgroundcolor on ActionBar (Toolbar) and in ActionBar pop up menu.
The latest approach in Android (as of May 2018) in working with Action bar (Toolbar) is to use Theme with NoActionBar and use Toolbar instead.
so here is what you need:
In Activity (which extends AppCompatActivity) declare Toolbar:
Add Toolbar in the Activity's layout xml. Here we will set our custom (overwritten themes), note
android:theme="@style/ThemeOverlay.AppTheme.ActionBar"
andapp:popupTheme="@style/ThemeOverlay.AppTheme.PopupMenu"
, they will do the trick.In your styles.xml you will have to overwrite those two styles to set custom colors:
That's it folks
p.s. if you ask me I would say: YES, this whole Theme thing is a hell of a mess.
Found the way to do it nicely without creating your own layout on API >= 21.
It will only colorize texts and control drawables inside the action bar.
Hope it will be useful for someone.
If you want to style the subtitle also then simply add this in your custom style.
People who are looking to get the same result for
AppCompat
library then this is what I used:The most straight-forward way is to do this in the styles.xml.
Google's template styles.xml currently generates the following:
If you add one more line before the closing tag, as shown, that will change the text color to what it should be with a Dark ActionBar:
If you want to customize the color to something else, you can either specify your own color in colors.xml or even use a built-in color from Android using the android:textColorPrimary attribute:
Note: This changes the color of the title and also the titles of any MenuItems displayed in the ActionBar.
This is not the recommended solution as I am going in android apis here but as my application requires to change the theme dynmically on conditions xml not possible here, So I need to do this. But This solution is working very nice.
Solution:--