Change Toolbar Color in Appcompat 21

Change Toolbar color in Appcompat 21

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

<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.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

How to change AppCompat v21 toolbar theme programmatically?

You can do this programmatically or with style:

Toolbar toolbar; // your toolbar
toolbar.setBackgroundColor(newColor); // i don't tested this method. Write if it's not working
toolbar.setTitleTextColor(titleColor); // if toolbar is white set title to black, if toolbar is black set title to white

Or you can do it with style:

Add attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="toolbarStyle" format="reference"/>
</resources>

And now change 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_width="match_parent"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
android:layout_height="@dimen/toolbar_height"
app:theme="?attr/toolbarStyle"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@color/primary_color">

</android.support.v7.widget.Toolbar>

And in styles.xml (if you don't have this create it):

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyStyle.Dark" parent="AppCompat.Theme">
<item name="toolbarStyle">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
<style name="MyStyle.Light" parent="AppCompat.Theme.Light">
<item name="toolbarStyle">@style/ThemeOverlay.AppCompat.Light.ActionBar</item>
</style>
</resources>

If you select second method (with styles) you must restart activity and use setTheme method before super.onCreate()

I hope I helped you.

How to change color of Toolbar back button in Android?

use this style

<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">@drawable/back_button_image</item>
</style>

Wrong color in toolbar items MaterialButton on Api 21

I managed to fix it myself. The problem was the default background was set with
?attr/colorPrimary. I made new colors xml for API 21 and set it like this @color/colorPrimary. I don't know if it's the best fix. If anyone has a better answer please write it.

AppCompat Toolbar: Change Overflow Icon Color in ActionMode

Add the below line into your theme attribute:

<item name="android:textColorSecondary">@android:color/white</item>

How to change color of toolbar options background

Try this in your Toolbar:

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

AppCompat ToolBar popupTheme not used in the ShareAction MenuItem

And here is with AppBarLayout:

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbarmain"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/ColorPrimary"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

Take a look at this also:

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"


Related Topics



Leave a reply



Submit