Ashkan Sarlak
Ashkan Sarlak

Reputation: 7344

Cannot make status bar translucent

EDIT: The more relevant question is posted here: MaterialDrawer library turns a translucent status bar into a opaque one


I know it can be done in API19+. Also I have read this and this and it seems that it can be done very easily. However I can't get it done. Here is my theme in values-v19 folder:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

I have also changed the appcompat theme to Theme.Holo.Light.NoActionBar.TranslucentDecor (and of course using Activity instead of AppCompatActivity); Nothing changed.

This is the screen shot from genymotion emulator api-22 (solid status bar; same result on real device):

enter image description here

And now here's the weird thing: In the preview window of the layout, when you select api-23 (on both appcompat and holo themes), I get this result (translucent):

enter image description here

and the preview for api-19 (also api-21 and 22) is this:

enter image description here

It's very confusing and I don't know what have I done wrong. Any help would be appreciated.

EDIT:

If I add:

<item name="colorPrimaryDark">@color/primary_dark</item>

the solid status bar changes color:

enter image description here

The other weird thing is the navigation drawer goes beyond the damn bar:

enter image description here

Upvotes: 0

Views: 568

Answers (2)

Lance
Lance

Reputation: 741

This worked for me, added in styles-v21.xml:

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

and in activity_main.xml under android.support.v4.widget.DrawerLayout:

    android:android:fitsSystemWindows="true">

styles-v21.xml

<style name="AppTheme" parent="AppTheme.Base">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

styles.xml

<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

activity_main.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

       <include
            android:id="@id/app_bar"
            layout="@layout/app_bar" />

        <FrameLayout
            android:id="@id/container_body"
            android:layout_width="fill_parent"
            android:layout_gravity="center"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </FrameLayout>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view"/>
</android.support.v4.widget.DrawerLayout>

app_bar.xml

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>

Upvotes: 1

Ashkan Sarlak
Ashkan Sarlak

Reputation: 7344

I finally found the source of the problem. I was using MaterialDrawer library for adding a drawer to my activity. When I removed it, everything worked perfectly. I will post another question to issue this problem and will add the link to that in an edit.

Upvotes: 0

Related Questions