I am trying out AppCompat on Marshmallow. And I want to have a transparent status bar however it turns white. I\'ve tried a couple solutions but they didn\'t work for me (Tr
(A little late to the party but it might help someone)
I had the exact same problem. Somehow, some activities were normal while new ones I created were showing white status bar instead of colorPrimaryDark
value.
After trying several tips, I noticed that the normal-working activities where all using CoordinatorLayout
as the root of the layout, while for the others I had replaced it by regular layouts because I didn't need the features (animation, etc) provided by CoordinatorLayout
.
So the solution is to make CoordinatorLayout
the root layout, and then inside of it add your former layout root. Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<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/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<!-- your activity content here-->
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
PLEASE NOTE that without android:fitsSystemWindows="true"
this solution doesn't work for me.
Tested on Lollipop and Marshmallow
I'm not sure if it's late but i hope it helps someone. * Make a fake view with transparent background that fits the layout, and make a coordinatorlayout as your root layout element.
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:fitsSystemWindows="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/something" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.... YOUR LAYOUT
you want this right?
try this. in [value] - [style.xml]
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:windowLightStatusBar">true</item>
</style>
you know, don't match apptheme - parent
good luck
For me it worked by doing the following :
.NoActionBar
android.support.design.widget.AppBarLayout
android.support.design.widget.CoordinatorLayout
as the parent layout. Essentially it is the third step that draws the status bar in the colorPrimaryDark
otherwise it is not drawn if you using NoActionBar
theme.
2nd step will give your toolbar that overlay.
If your v21/styles.xml contain
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
Then, Remove or comment below line or change colour of status bar,
<item name="android:statusBarColor">@android:color/transparent</item>
Its working fine. Hope this is helpful. Thanks.
You have to add this property on your style to see the content
<item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item>