Search code examples
androidandroid-statusbar

Toolbar color not extending to status bar


Update:Manifest added

For some reason the status bar is not showing the dark primary color, but it is translucent on my Nexus 5 @ 5.1.1 Lollipop. Watch the video here: http://sendvid.com/vo5b5a83

As you can see, when the app starts, the color of the status bar is red, but when it enters the launch activity, it changes back to grey, and it is translucent. Here are the codes:

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:colorPrimary">@color/primary_color</item>
    <item name="android:colorPrimaryDark">@color/primary_dark_color</item>
</style>

activity_main.xml

<RelativeLayout...>
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/primary_dark_color"
            app:layout_scrollFlags="scroll|enterAlways"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways"
            app:tabMaxWidth="0dp"/>

    </android.support.design.widget.AppBarLayout>
...
</RelativeLayout>

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:name="..."
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

I have tried several solutions on fixing non-transparent status bar, but none of them work, since I don't think that is the problem at all.


Solution

  • You should use "colorPrimary" and "colorPrimaryDark" without the "android:", so it would look like this:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primary_color</item>
        <item name="colorPrimaryDark">@color/primary_dark_color</item>
    </style>
    

    Let me know if that helps!