Reputation: 10437
Toolbar background is dark color, I want text and back arrow to be white. I tried following, but it doesnt work.
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/blue</item>
<item name="colorPrimaryDark">@color/blue_darker</item>
<item name="colorAccent">@color/purple</item>
<!-- item name="android:textColorPrimary">@color/white</item--> // I don't want to set this, changes everywhere.
<item name="android:textColorSecondary">@color/white</item>
<item name="android:toolbarStyle">@style/AppTheme.ToolbarStyle</item>
<item name="toolbarStyle">@style/AppTheme.ToolbarStyle</item>
<item name="drawerArrowStyle">@style/AppTheme.DrawerArrowStyle</item>
</style>
<style name="AppTheme.ToolbarStyle" parent="Base.Widget.AppCompat.Toolbar">
<!--<item name="actionOverflowButtonStyle">@style/AppTheme.OverflowButtonStyle</item>-->
<item name="android:textColor">@color/white</item> // doesn't work
<item name="titleTextAppearance">@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse</item>
<item name="android:titleTextAppearance">@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse</item>
<item name="subtitleTextAppearance">@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle</item>
</style>
Upvotes: 134
Views: 205075
Reputation: 1420
<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/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_primary"
android:theme="@style/GalaxyZooThemeToolbarDarkOverflow"
app:popupTheme="@style/Theme.AppCompat.NoActionBar" />
That toolbar theme specifies a textColorPrimary and textColorSecondary to change the color of the title text and of the menu overflow button. You could just specify the standard Theme.AppCompat.Light.NoActionBar theme for the toolbar, to get the dark text and overflow icon, but I wanted to derive from my own theme and make only small changes, because I have no idea what else might be affected.
<style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
<!-- android:textColorPrimary is the color of the title text
in the Toolbar, in the Theme.AppCompat theme: -->
<item name="android:textColorPrimary">@color/abc_primary_text_material_light</item>
<!-- android:textColorPrimaryInverse is the color of the title
text in the Toolbar, in the Theme.AppCompat.Light theme: -->
<!-- <item name="android:textColorPrimaryInverse">@color/abc_primary_text_material_light</item> -->
This is how you can change the color of text and icons on toolbar.
For more Ref: https://www.murrayc.com/permalink/2014/10/28/android-changing-the-toolbars-text-color-and-overflow-icon-color/
Upvotes: 1
Reputation: 11
Add this lines in Basic application theme, first for text, second for icon of menu
<item name="android:textColorPrimary">@color/colorTextWhite</item>
<item name="android:textColorSecondary">@color/colorTextWhite</item>
It would look like this
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:textColorPrimary">@color/colorTextWhite</item>
<item name="android:textColorSecondary">@color/colorTextWhite</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Upvotes: 1
Reputation: 117
Add this line to Toolbar
. 100% working
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
Upvotes: 5
Reputation: 42377
This approach worked for me using the Material Components library:
In styles.xml
:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Your styles here -->
<item name="toolbarStyle">@style/AppTheme.Toolbar</item>
</style>
<style name="AppTheme.Toolbar" parent="Widget.MaterialComponents.Toolbar">
<item name="titleTextColor">@android:color/white</item>
</style>
Adapted from this answer: https://stackoverflow.com/a/48205577/238753
Upvotes: 4
Reputation: 1751
If you use AndroidX
(as of July 2019)
you may add these:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="pin"
app:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.MaterialComponents.Light"/>
NOTE! This was tested to work if your Toolbar
is placed directly inside AppBarLayout
but not inside CollapsingToolbarLayout
Upvotes: 19
Reputation: 477
This solution might be easier. But it does require a higher API version(23). simply add this code to your toolbar in XML:
<Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:titleTextColor="#ffffffff" />
Upvotes: 25
Reputation: 351
If we follow the activity template created by Android Studios, it's the AppBarLayout that needs to have an android theme of AppBarOverlay, which you should define in the your styles.xml. That should give you your white color toobar/actionbar color text.
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"> ...
In styles.xml, make sure the following exists:
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
Upvotes: 1
Reputation: 6931
Inside Activity, you can use
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
If you love to choose xml for both title color & back arrow white just add this style in style.xml .
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="actionMenuTextColor">@android:color/white</item>
</style>
And toolbar look like :
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:theme="@style/ToolBarStyle"
android:layout_height="?attr/actionBarSize"
/>
Upvotes: 67
Reputation: 256
this method helped me.
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/highlightRed</item>
<item name="actionBarTheme">@style/ToolbarStyle</item>
</style>
<style name="ToolbarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/white</item>
</style>
Upvotes: 14
Reputation: 345
If using the latest iteration of Android Studio 3.0 and generating your Activity classes, in your styles files change this:
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
To this:
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.ActionBar" />
Upvotes: 0
Reputation: 4910
Try this on your XML file
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:titleTextColor="@color/colorAccent"
app:theme="@style/ToolbarColoredBackArrow"
app:subtitleTextColor="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
And add this is your colors.xml file
<color name="colorAccent">YOUR_COLOR</color>
Upvotes: 3
Reputation: 3879
Add the following as toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<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/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary">
</android.support.v7.widget.Toolbar>
Then in the layout where you needed
<include layout="@layout/toolbar"/>
Enjoy
Upvotes: 136
Reputation: 2757
I used placeholders so just follow along, as you might want to still keep the inheritance from the original style.
Before
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/{{originalBaseStyle}}"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
After:
styles.xml
<style name="{{yourToolbarStyle}}" parent="{{originalBaseStyle}}">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="actionMenuTextColor">@android:color/white</item>
<item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
Therefore
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/{{yourToolbarStyle}}"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
Upvotes: 1
Reputation: 1703
Chances are you are extending from the wrong parent. If not, you can try adding the style
to the toolbar
layout directly, if you want to override the theme's settings.
In your toolbar layout:
<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/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ToolBarStyle"
app:popupTheme="@style/ToolBarPopupStyle"
android:background="@color/actionbar_color" />
In your styles:
<!-- ToolBar -->
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="actionMenuTextColor">@android:color/white</item>
<item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
Upvotes: 163
Reputation: 2418
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimaryDark"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
Upvotes: 9
Reputation: 35
Try a lot of methods, in the low version of the API,a feasible method is <item name="actionMenuTextColor">@color/your_color</item>
and don't use the Android namespace
ps:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- change the textColor -->
<item name="actionMenuTextColor">@color/actionMenuTextColor</item>
</style>
Upvotes: 1
Reputation: 562
To change the Toolbar's back icon drawable you can use this:
Add the <item name="toolbarStyle">@style/ToolbarStyle</item>
into your Theme.
And here is the ToolbarStyle
itself:
<style name="ToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="navigationIcon">@drawable/ic_up_indicator</item>
</style>
Upvotes: 0
Reputation: 1024
<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/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/actionBar"
app:titleTextAppearance="@style/ToolbarTitleText"
app:theme="@style/ToolBarStyle">
<TextView
android:id="@+id/title"
style="@style/ToolbarTitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="hh"/>
<!-- ToolBar -->
<style name="ToolBarStyle" parent="Widget.AppCompat.Toolbar">
<item name="actionMenuTextColor">#ff63BBF7</item>
</style>
use app:theme="@style/ToolBarStyle"
Reference resources:http://blog.csdn.net/wyyl1/article/details/45972371
Upvotes: 6