Search code examples
androidandroid-statusbar

Transparent statusbar is not tinted properly


I have a problem with StatusBar, I've managed to implement styles for it like this:

<resources>
    <style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimaryDark">#59000000</item>
        <item name="android:statusBarColor">#59000000</item>
        <item name="colorAccent">@color/blueAppBar</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>

But activity doesn't work with it properly and goes like this:enter image description here

As you see status bar is not tinted and goes just blue, like background. What should I do to make it tinted?


Solution

  • You shouldn't use android:windowTranslucentStatus and android:statusBarColor together.

    You should use android:windowTranslucentStatus in values-v19 and android:statusBarColor in values-v21.

    This is a sample configuration:

    values/styles.xml

    <resources>
    
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="colorPrimaryDark">#59000000</item>
            <item name="colorAccent">@color/blueAppBar</item>
        </style>
    
        <style name="AppTheme.NoActionBar">
        </style>
    </resources>
    

    values-v19/styles.xml

    <resources>
        <style name="AppTheme.NoActionBar">
            <item name="android:windowTranslucentStatus">true</item>
        </style>
    </resources>
    

    values-v21/styles.xml

    <resources>
        <style name="AppTheme.NoActionBar">
            <item name="android:statusBarColor">#59000000</item>
        </style>
    </resources>
    

    AndroidManifest.xml

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