How to change toolbar color

Selorbis picture Selorbis · Aug 26, 2015 · Viewed 55.9k times · Source

I've been searching how to customize the toolbar, for example how to add background color, but I don't understand how it works.

I've been trying to add a custom style for my toolbar but any result ...

The Manifest

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.Design">

The style.xml file

<resources>

    <style name="Theme.Design" parent="Base.Theme.Design">
    </style>

    <style name="Base.Theme.Design" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/red</item>
        <item name="colorPrimaryDark">@color/red</item>
        <item name="colorAccent">@color/red</item>
        <item name="android:textColorPrimary">@color/white</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="windowActionBarOverlay">true</item>
    </style>    
    ...

And the toolbar in layout

<android.support.v7.widget.Toolbar
            android:id="@+id/home_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>

Answer

Selorbis picture Selorbis · Aug 27, 2015

Thanks, but any solution works.

 <android.support.v7.widget.Toolbar
            android:id="@+id/home_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"/>

or

toolbar.setBackgroundColor(Color.parseColor("#80000000"));

May be because my toolbar is in android.support.design.widget.CoordinatorLayout (to put a android.support.design.widget.FloatingActionButton) ?