Currently I am using material components and material theme:
<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
...
<item name="materialButtonStyle">#style/Button</item>
</style>
I was able to define a style for every button using materialButtonStyle and I was wondering if it is possible to achieve the same for a toolbar.
THIS IS REALLY IMPORTANT: The idea is to avoid defining a style / theme in the appbar or toolbar component, but just use it a get the styles defined by the app theme.
I want to avoid this:
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:theme="#style/ToolbarTheme">
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextAppearance="#style/ToolbarTextAppearance"
tools:title="Title" />
</com.google.android.material.appbar.AppBarLayout>
Inside the theme I want to be able to specify the font style and the text appearance.
These are my style:
<style name="ToolbarTheme" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar">
</style>
<style name="ToolbarTextAppearance" parent="TextAppearance.AppCompat.Title">
<item name="android:fontFamily">#font/nunito_bold</item>
</style>
Using the code defined previously, I am able to get those changes. But as I mentioned, I want to defined that as part of my app theme like the material button.
I tried using this but I did not succeed:
<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
<item name="appBarLayoutStyle">#style/ToolbarTheme</item>
<item name="toolbarStyle">#style/ToolbarTheme</item>
</style>
This code works for me just fine:
<resources>
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="appBarLayoutStyle">#style/AppTheme.AppBarOverlay</item>
<item name="toolbarStyle">#style/AppTheme.Toolbar</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar">
<item name="android:background">?colorPrimary</item>
</style>
<style name="AppTheme.Toolbar" parent="Widget.MaterialComponents.Toolbar">
<item name="titleTextAppearance">#style/TextAppearance.MaterialComponents.Body1</item>
</style>
</resources>
You can add in your app theme the toolbarStyle attribute:
<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="toolbarStyle">#style/MyToolbar</item>
</style>
Then define your custom style:
<style name="MyToolbar" parent="#style/Widget.MaterialComponents.Toolbar">
<item name="titleTextAppearance">#style/MyToolbartitleTextAppearance</item>
</style>
<style name="MyToolbartitleTextAppearance" parent="#style/TextAppearance.MaterialComponents.Headline6">
...
<item name="fontFamily">....</item>
<item name="android:fontFamily">....</item>
</style>
In your layout use the com.google.android.material.appbar.MaterialToolbar.
To define globally a style for the AppBarLayout use in your app theme the attribute (in your case is not clear what you want to customize).
<item name="appBarLayoutStyle">#style/...</item>
In Styles file add this:
<style name="MyToolbarStyle" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">?attr/color_text_primary</item>
<item name="android:textSize">20sp</item>
<item name="android:fontFamily">sans-serif-smallcaps</item>
</style>
Then in your MainActivity class:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitleTextAppearance(this, R.style.MyToolbarStyle);
Related
I am trying to customize the look of Toolbar in my app.
Target
I would like to set the title color and the background color of the Toolbar.
I read about how Theme and Style works, so I was able to try some solutions.
I found out that title color is managed by app:titleTextColor property and the background color from the android:background attribute.
Premise
To know how to act it is necessary to know how the style of the widget that we need to modify is managed.
The base Toolbar style is defined in the Widget.MaterialComponents.Toolbar style as below.
<style name="Widget.MaterialComponents.Toolbar" parent="Widget.AppCompat.Toolbar">
<item name="titleTextAppearance">?attr/textAppearanceHeadline6</item>
<item name="titleTextColor">?android:attr/textColorPrimary</item>
<item name="subtitleTextAppearance">?attr/textAppearanceSubtitle1</item>
<item name="subtitleTextColor">?android:attr/textColorSecondary</item>
<!-- Overrides minimum height in landscape to avoid headline6 and subtitle1 height concerns. -->
<item name="android:minHeight">#dimen/mtrl_toolbar_default_height</item>
<item name="maxButtonHeight">#dimen/mtrl_toolbar_default_height</item>
</style>
Here the value of titleTextColor is set to ?android:attr/textColorPrimary.
So my first attempt was simply to add the ovverride of android:textColorPrimary attribute in my app theme.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:textColorPrimary">#color/white</item>
</style>
Result: This works.
To also set the background I decided to create a custom Toolbar style where to put the background definition, so I changed my theme as below.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
<!-- Customize your theme here. -->
<item name="toolbarStyle">#style/MyToolbarStyle</item>
</style>
<style name="MyToolbarStyle" parent="Widget.MaterialComponents.Toolbar">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:background">?attr/colorPrimary</item>
</style>
Result: This does not works. The android:background is applied but the android:textColorPrimary not.
Setting the value of titleTextColor directly inside MyToolbarStyle works.
<style name="MyToolbarStyle" parent="Widget.MaterialComponents.Toolbar">
<item name="titleTextColor">?attr/colorOnPrimary</item>
<item name="android:background">?attr/colorPrimary</item>
</style>
I also tried to set the toolbar theme where I override the Android attribute:textColorPrimary, as below.
<style name="Base_ToolbarStyle" parent="Widget.MaterialComponents.Toolbar">
<item name="android:background">?attr/colorPrimary</item>
<item name="android:theme">#style/Base_ToolbarTheme</item>
</style>
<style name="Base_ToolbarTheme">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
</style>
Result: This does not works too.
Now I am a bit confused from the outcome of my tests.
Why is it not possible to override the android:textColorPrimary in the custom style?
To apply a style you can use (and the toolbarStyle attribute applies this style to all the Toolbar) the style attribute:
<androidx.appcompat.widget.Toolbar
style="#style/MyToolbarStyle"
with:
<style name="MyToolbarStyle" parent="Widget.MaterialComponents.Toolbar">
<item name="titleTextColor">?attr/colorOnPrimary</item>
<item name="android:background">?attr/colorPrimary</item>
</style>
because titleTextColor is a property defined in the Toolbar.
To apply a theme overlay you can use the android:theme attribute:
<androidx.appcompat.widget.Toolbar
android:theme="#style/MyToolbarThemeOverlay"
with
<style name="MyToolbarThemeOverlay">
<item name="android:textColorPrimary">#color/white</item>
</style>
because android:textColorPrimary is an attribute defined at theme level.
If you want to override a theme attribute directly in a style you have to use the materialThemeOverlay attribute:
<style name="MyToolbarStyle" parent="Widget.MaterialComponents.Toolbar">
<item name="android:background">?attr/colorPrimary</item>
<item name="materialThemeOverlay">#style/MyToolbarThemeOverlay</item>
</style>
With using the AppCompat Material Toolbar androidx.appcompat.widget.Toolbar, I have made the following definitions to customize the Toolbar in a theme
Given this toolbar in a layout file:
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/MyAppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:popupTheme="#style/MyAppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
Define a toolbar style in themes.xml:
<style name="MyAppTheme.Toolbar" parent="Widget.MaterialComponents.Toolbar">
<!-- Add custom stuff here -->
<item name="android:background" tools:targetApi="l">#color/dark_primary</item>
<item name="background">#color/dark_primary</item>
</style>
And also add the overlay styles in themes.xml:
<style name="MyAppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="MyAppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
And then apply in app theme:
<style name="MyAppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
...
<item name="android:toolbarStyle" tools:targetApi="l">#style/MyAppTheme.Toolbar</item>
<item name="toolbarStyle">#style/MyAppTheme.Toolbar</item>
...
</style>
At first, My app use <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> style. But I changed it to Material Components <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar"> (in order to use the tab's badge count of Material). So the style after changing is like this:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/green</item>
<item name="colorPrimaryDark">#color/green</item>
<item name="colorAccent">#color/green</item>
</style>
After changing the style, the overflow menu background is now white. (It was green background with white text before with Theme.AppCompat.Light.DarkActionBar). But now the background is white, and the text is also white.
Here is the xml for the toolbar:
<androidx.appcompat.widget.Toolbar
android:id="#+id/ev_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ToolbarTheme">
</androidx.appcompat.widget.Toolbar>
and theme style of the toolbar:
<style name="ToolbarTheme" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:colorBackground">#color/green</item>
</style>
I tried setting <item name="popupMenuStyle">#style/CustomPopup</item> in the AppTheme with
<style name="CustomPopup" parent="#style/Widget.MaterialComponents.PopupMenu">
<item name="android:popupBackground">#color/green</item>
</style>
but still no luck.
The device I use to test uses Android 8.0, compileSdkVersion and targetSdkVersion is 28.
Thank you for your time.
The background color of the popup in overflow menu is defined in the app theme by the attribute actionOverflowMenuStyle.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="actionOverflowMenuStyle">#style/Widget.MaterialComponents.PopupMenu.Overflow</item>
</style>
The 1.2.0-alpha02 fixed a mixing between light and dark theme for this value.
You can also customize the popup using:
<com.google.android.material.appbar.MaterialToolbar
app:popupTheme="#style/AppTheme.PopupOverlay"
../>
with:
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="android:popupBackground">#drawable/...</item>
</style>
You can also override the color without changing the drawable using the android:theme attribute in the Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:theme="#style/MyThemeOverlay_Toolbar"
../>
Using:
<style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<item name="colorSurface">#color/custom</item>
</style>
Another twist to the accepted answer above using MaterialComponents.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="actionOverflowMenuStyle">#style/Theme.MyApp.PopupOverlay3</item>
</style>
<style name="Theme.MyApp.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.MyApp.PopupOverlay3" parent="#style/Widget.MaterialComponents.PopupMenu.Overflow">
<item name="android:popupBackground">#color/black</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>
<style name="Theme.MyApp.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.MyApp.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
the key is, as you say the actionOverflowMenuStyle attribute is the key to success. Set this to a style which uses the Widget.MaterialComponents.PopupMenu.Overflow style. And then change the attributes you want to customize for the overflow menu.
RG
you should add this code into toolbar, it will work
<androidx.appcompat.widget.Toolbar
android:id="#+id/ev_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:minHeight="?attr/actionBarSize"
**android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light**">
</androidx.appcompat.widget.Toolbar>
In my activity, I use default ActionBar
<style name="AppTheme" parent="Theme.AppCompat"> and getSupportActionBar()
How can I custom the style of this ActionBar?
Change ActionBar color and title color
Align title to center
Add more top padding to ActionBar
For the color, I tried these two style, but it also change color of whole Activity, I just want to change ActionBar
<item name="colorPrimary"></item>
<item name="android:textColorPrimary"></item>
I alo tried actionBarStyle, but it is not working
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">#color/darkgray</item>
<item name="colorPrimaryDark">#color/black</item>
<item name="colorAccent">#color/gold</item>
<item name="android:textColorPrimary">#color/gold</item>
<item name="android:textColorSecondary">#color/darkgray</item>
<item name="android:windowBackground">#color/black</item>
<item name="android:colorBackground">#color/black</item>
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/gray</item>
<item name="android:textColor">#color/black</item>
</style>
I suggest you to include the Toolbar in your layout and use the Theme.AppCompat.NoActionBar theme for your Activity :
Layout :
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/yourColor">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#color/yourColor"
android:text="yourTitle" />
</android.support.v7.widget.Toolbar>
Manifest :
<activity
android:name="yourActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
I want to change the Action Bar color, but I don't know how to do it. What should I add to change the style?
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
This is all you need to change the color of the action bar:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#995544</item>
</style>
That code works for me and it also changes text color
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="background">#color/colorPrimary</item>
<item name="android:height">150dp</item>
<item name="height">60dp</item>
</style>
<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">15dp</item>
<item name="android:textColor">#color/colorAccent</item>
</style>
simple a single Line code
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.red)));
If your minSdk is 21 or higher, you can add the following:
<item name="colorPrimary">#color/yourColor</item>
If not then make the following changes:
Your activity must extend AppCompatActivity
Change your theme to #style/Theme.AppCompat.Light.NoActionBar
Add this to the top of your activity xml file:
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
Put this in your onCreate method after the super.onCreate call:
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
To change the color just replace ?attr/colorPrimary with #color/yourColor
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
</style
Here colorPrimary attribute helps you to change the color of action bar.
For more details see this fig.
Please try the code below:
<style name="AppCompatTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#ff540e9e</item>
<item name="android:textColor">#ffffff</item>
</style>
At your theme.xml or/and theme.xml (dark), change the following android:statusBarColor which change the to status bar background color, toolbarNavigationButtonStyle change the back button color, actionBarStyle change the background and text color and displayOptions to show the text.
<style name="Theme.Example" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Status bar color. -->
<item name="android:statusBarColor">#color/backgroundDark</item>
<!-- action bar color. -->
<item name="toolbarNavigationButtonStyle">#style/Toolbar.Button.Navigation.Tinted</item>
<item name="actionBarStyle">#style/Actionbar.dark</item>
<item name="displayOptions">showHome|useLogo|showTitle</item>
</style>
<style name="Actionbar.dark" parent="Widget.AppCompat.Toolbar.Button.Navigation">
<item name="background">#color/backgroundDark</item>
<item name="titleTextStyle">#style/Actionbar.darktext</item>
</style>
<style name="Actionbar.darktext" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
<style name="Toolbar.Button.Navigation.Tinted" parent="Widget.AppCompat.Toolbar.Button.Navigation">
<item name="tint">#color/white</item>
</style>
You can customize the current theme for your app, in the res/values/styles.xml file try:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
// your custom styles added to theme
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
</style>
//Cutomise your theme by specifying layout,color, font type etc:
<style name="MyActionBarTheme"
parent="#android:style/Widget.AppCompat.Light.DarkActionBar">
// sets the background color of the activity/app:
<item name="android:background">#33FF33</item>
</style>
Then you will need to add your new custom theme name to your apps Manifest file
I am learning to design Android apps using new Material Design themes. And while designing a custom ToolBar I was trying to give a custom color to the title inside the my custom ToolBar.
On Android Lollipop device it is working fine as expected, as you can see in the image link given below, but when i tried it to run on the pre-Lollipop device, I am not getting the same result. Why so? I have attached the code below.
Here I have attached the screenshot of both, Lollipop version as well as pre-Lollipop version screens.
Lollipop version which shows it correctly
pre-Lollipop version which is not giving the expected output.
Code:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<TextView
android:layout_marginTop="10dp"
android:layout_below="#+id/app_bar"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#455A64</item>
<item name="colorPrimaryDark">#607D8B</item>
<item name="colorAccent">#9E9E9E</item>
</style>
<style name="CustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#D32F2F</item>
<item name="android:textColorSecondary">#F44336</item>
</style>
</resources>
app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1976D2"
android:theme="#style/CustomToolbarTheme"
android:popupTheme="#style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
P.S.: If this Question (or similar) is already been answered here, then please comment the link here. Thank You!
You're using
android:theme="#style/CustomToolbarTheme"
which is this:
<style name="CustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#D32F2F</item>
<item name="android:textColorSecondary">#F44336</item>
</style>
It's not overriding the colorPrimary attribute like AppTheme.Base is. Add that line to this style and make sure the background is set to it, like this:
<style name="CustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:background">?attr/colorPrimary</item>
<item name="colorPrimary">#455A64</item>
<item name="android:textColorPrimary">#D32F2F</item>
<item name="android:textColorSecondary">#F44336</item>
</style>
Try set titleTextAppearance for your Toolbar's theme, like this:
<style name="Toolbar" parent="Theme.AppCompat.Light">
<item name="titleTextAppearance">#style/Toolbar.TitleText</item>
</style>
<style name="Toolbar.TitleText">
<item name="android:textColor">#color/toolbar_title_text</item>
</style>
EDIT:
Sorry, I forgot to add that you should set one more thing.
<android.support.v7.widget.Toolbar
...
xmlns:app="http://schemas.android.com/apk/res-auto"
app:theme="#style/Toolbar"
app:titleTextAppearance="?attr/titleTextAppearance"/>
(Solution above can be used also for other text appearance's attributes, for example android:textStyle or android:textSize.)
if it not working then you can also set toolbar custom title colour and toolbar custom title at runtime. Code snippet is given below
private Toolbar toolbar;
toolbar = (Toolbar) findViewById(R.id.app_bar);
toolbar.setTitleTextColor(Color.parseColor("#FF557F"));
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Title");
I'm using this:
color.xml
<resources>
<color name="white">#fff</color>
<color name="primary">#673ab7</color>
<color name="primary_dark">#512da8</color>
<color name="accent">#ffc400</color>
<color name="text_primary">#009688</color>
<color name="text_secondary">#e2eef0</color>
</resources>
values/themes.xml
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/text_primary</item>
<item name="android:textColor">#color/text_secondary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
</resources>
values-v21/themes.xml
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/text_primary</item>
<item name="android:textColor">#color/text_secondary</item>
<item name="android:navigationBarColor">#color/primary_dark</item>
</style>
</resources>
See some tutorials:
material-design-everywhere
Android L Tutorials (Part 2): Material Theme Colors
you use this on your theme android:textColorPrimary , so instead use this textColorPrimary because the first is using just in v-21 on lollipop