I am testing out the new Appcompat 21 Material Design features. Therefore I've created a Toolbar like this:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_my_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
and included it in my main layout file.
Then I've set it as supportActionBar like that:
Toolbar toolBar = (Toolbar)findViewById(R.id.activity_my_toolbar);
setSupportActionBar(toolBar);
It's working, but somehow I can't quite figure out how to customize the toolbar. It's grey and the text on it is black. How should I change background and text color?
I've gone through this instructions:
http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html
What have I overseen to change colors?
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowActionBar" tools:ignore="NewApi">false</item>
<item name="windowActionBar">false</item>
</style>
EDIT:
I was able to change the background color by adding these lines of code to the theme:
<item name="colorPrimary">@color/actionbar</item>
<item name="colorPrimaryDark">@color/actionbar_dark</item>
But they won't affect the text color. What am I missing? Instead of the black text and black menu button, I'd rather prefer a white text and white menu buttons:
Hey if you want to apply Material theme for only android 5.0 then you can add this theme in it
Here below line is responsibly for text color of Actionbar of Material design.
For people who are using AppCompatActivity with Toolbar as white background. Do use this code.
Updated: December, 2017
Try this in your styles.xml:
colorPrimary will be the toolbar color.
Did you build this in Eclipse by the way?
If you want to change the color of your toolbar all throughout your app, leverage the styles.xml. In general, I avoid altering ui components in my java code unless I am trying to do something programatically. If this is a one time set, then you should be doing it in xml to make your code cleaner. Here is what your styles.xml will look like:
Make sure you use the above style in your AndroidManifext.xml as such:
I wanted different toolbar colors for different activities. So I leveraged styles again like this:
again, apply the styles to each activity in your AndroidManifest.xml as such:
again this is all in the link you supplied
to change the text to white all you have to do is change the theme.
use this theme
You can set a custom toolbar item color dynamically by creating a custom toolbar class:
then refer to it in your layout file. Now you can set a custom color using
Sources:
I found the information to do this here: How to dynamicaly change Android Toolbar icons color
and then I edited it, improved upon it, and posted it here: GitHub:AndroidDynamicToolbarItemColor