5

I'm using AppCompat for a backport of Material design on pre-Lollipop devices. Somehow, the support toolbar overlays the status bar and casts a shadow on it, as if the status bar is behind the toolbar. Tested on my Android 5.0.2 phone.

enter image description here

Here's the code:

Activity layout

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/base_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/base_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/PGTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/base_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/PGTheme.PopupOverlay"/>

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

</android.support.design.widget.CoordinatorLayout>

Theme-v21

<style name="PGTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/base_color_2</item>
    <item name="colorPrimaryDark">@color/base_color_1</item>
    <item name="colorAccent">@color/base_color_2</item>
    <item name="android:colorButtonNormal">@color/base_color_2</item>
    <item name="android:textViewStyle">@style/PGTheme.TextView</item>
    <item name="android:editTextStyle">@style/PGTheme.EditText</item>
    <item name="android:buttonStyle">@style/PGTheme.Button</item>
</style>

<style name="PGTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

Any idea why this happens?

Lucas Lages
  • 87
  • 1
  • 8

1 Answers1

10

In your Style remove the statusBarColor:

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

So your theme would be:

<style name="PGTheme.NoActionBar">
  <item name="windowActionBar">false</item>
  <item name="windowNoTitle">true</item>
  <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

Hope this helps.

bond
  • 11,236
  • 7
  • 48
  • 62
  • 1
    It works. And in the cases you want the status bar to be transparent, you can follow this post (and replace the color with Color.TRANSPARENT): http://stackoverflow.com/questions/26702000/change-status-bar-color-with-appcompat-actionbaractivity – Alan Zhiliang Feng Mar 28 '16 at 14:47