Status bar turns white and does not show content behind it

前端 未结 26 2361
闹比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:29

    (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

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

    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
    

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

    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

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

    For me it worked by doing the following :

    1. Set the theme .NoActionBar
    2. Wrap the Toolbar in android.support.design.widget.AppBarLayout
    3. Make 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.

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

    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.

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

    You have to add this property on your style to see the content

    <item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item>
    
    0 讨论(0)
提交回复
热议问题