Status bar turns white and does not show content behind it

前端 未结 26 2362
闹比i
闹比i 2020-11-29 22:33

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

相关标签:
26条回答
  • 2020-11-29 23:13

    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.

    0 讨论(0)
  • 2020-11-29 23:13

    [Output]

    Expand res -> values -> styles directory from project panel.

    Open styles.xml (v21)

    USE ANY ONE FROM BELOW WAYS

    1. Change true to false in android:windowDrawsSystemBarBackgrounds property.
    2. Change @android:color/transparent to @color/colorPrimaryDark in android:statusBarColor property.
    3. Remove the android:statusBarColor propert line.
    0 讨论(0)
  • 2020-11-29 23:15
    <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

    0 讨论(0)
  • 2020-11-29 23:16

    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>
    
    0 讨论(0)
  • 2020-11-29 23:18

    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.

    0 讨论(0)
  • 2020-11-29 23:18

    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);
    
    0 讨论(0)
提交回复
热议问题