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
After unsuccessfully trying all of the above I found that explicitly setting the theme fixed the issue.
setTheme(R.style.AppTheme);
That has to go before the super.OnCreate() in your activity.
[
Expand res -> values -> styles directory from project panel.
Open styles.xml (v21)
USE ANY ONE FROM BELOW WAYS
android:windowDrawsSystemBarBackgrounds
property.android:statusBarColor
property.android:statusBarColor
propert line.<item name="android:statusBarColor">@android:color/transparent</item>
You'll see that line of code in values/styles/styles.xml(v21) . Remove it and that solves the issue
Link to this answer
Better approach
Check your style.xml file where your NoActionBar theme is there. Make sure its has parent as Theme.AppCompat.NoActionBar and also customize it by adding your color scheme. Finally set your themes in manifest as required.
Below is sample of my styles.xml file (ActionBar + NoActionBar).
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- No ActionBar application theme. -->
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
I found the answer in this link:Status Bar Color not changing with Relative Layout as root element
So it turns out we need remove the
<item name="android:statusBarColor">@android:color/transparent</item>
in styles.xml(v21). And it works just fine for me.
Add this in your style.xml
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
and this in your onCreate();
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);