10

I have create a simple app with 2 activities. Main (launcher) activity is themed properly where colorPrimaryDark is applied to status bar. But when I transition to new activity, everything seems normal except status bar. It somehow colored white. Any idea why this could be happening?

Running this on OnePlus One (Lollipop 5.0.2)

Target api -> 16+

enter image description here

values/styles.xml

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/PrimaryColor</item>
    <item name="colorPrimaryDark">@color/PrimaryDarkColor</item>
    <item name="colorAccent">@color/accent</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

values-v21/styles.xml

<style name="AppTheme" parent="AppTheme.Base">
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/slide_bottom</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

layout/activity_settings.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#856"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context=".SettingsActivity">

    <include layout="@layout/toolbar" />

</LinearLayout>
Andy
  • 321
  • 1
  • 3
  • 11
  • Maybe [this](http://stackoverflow.com/questions/28289477/transparent-status-bar-not-working-with-windowtranslucentnavigation-false) will help you out – Strider Jun 18 '15 at 06:39

4 Answers4

8

Change

<item name="android:statusBarColor">@android:color/transparent</item>

to

<item name="android:statusBarColor">@color/PrimaryDarkColor</item>
Pyrmont
  • 256
  • 1
  • 6
  • Shouldn't this affect the main launcher activity as well? PrimaryColorDark is automatically applied to main activity with these settings. – Andy Jun 18 '15 at 06:56
  • I believe it appears grey as you are setting the statusBarColor to transparent. Try removing that line entirely – Pyrmont Jun 18 '15 at 07:12
  • 2
    If I change or remove above style, then my navigation drawer in the main activity loses one feature which draws the nav drawer under status bar. Like in this [image](http://3.bp.blogspot.com/-WmBBQQEJIKM/VWikAyy08sI/AAAAAAAABvc/1R36Txk83UI/s400/drawer.png) So I kept the style as is and set changed the status bar color programmatically in the concerned activity: getWindow().setStatusBarColor(getResources().getColor(R.color.PrimaryDarkColor)); – Andy Jun 18 '15 at 14:48
  • 1
    But it has to be in **values-v21/styles.xml** – Roon13 Jan 15 '16 at 17:37
1

Change the api level to 11+, you can find it. change the Theme to DarkActionBar

Shivputra N
  • 688
  • 7
  • 17
1

You might be not needing this anymore but I recently get this issue so maybe this will help others.

I fix it by creating new style in values-v21/styles.xml extending from the AppTheme:

<style name="AppTheme.SolidStatusBar">
    <item name="android:statusBarColor">@color/PrimaryDarkColor</item>
</style>

and use this as your new Activity theme in manifest. This way your changes don't have to interfere with activities that need to use translucent status bar like your Main activity.

I have no idea why is this happening though.

kasyauqi
  • 635
  • 1
  • 6
  • 17
0

In values-v21/styles.xml, change

<item name="android:statusBarColor">@android:color/transparent</item>

to

<item name="android:statusBarColor">@color/colorPrimaryDark</item>
Tunaki
  • 132,869
  • 46
  • 340
  • 423