代码之家  ›  专栏  ›  技术社区  ›  Soren Stoutner

当针对API28(Android 9)时,Android半透明状态栏总是灰色的,带有fitsSystemWindows

  •  4
  • Soren Stoutner  · 技术社区  · 6 年前

    从API 21开始,当样式包括 <item name="android:windowTranslucentStatus">true</item> android:fitsSystemWindows="true" 状态栏变为半透明,抽屉布局(如导航抽屉)在状态栏后面滑动。在将API 28作为目标之前,状态栏的基色将由 colorPrimaryDark android:statusBarColor

    这个问题实际上是在 com.android.support:design:27.1.0 ,但当时我认为这是一个bug并继续使用 com.android.support:design:27.0.2 . 随着对API28的继承,这似乎是一个未记录的设计更改。那么,在使用 fitsSystemWindows API=28时?

    1 回复  |  直到 6 年前
        1
  •  5
  •   Soren Stoutner    6 年前

    原来这个问题的答案是,基本状态栏颜色现在由设置为的布局项的背景设置 fitsSystemWindows . 然后,半透明的状态栏scrim会使该颜色变暗。所以,就我而言, 安装系统窗口 CoordinatorLayout 在一个 DrawerLayout . 设置 android:background 允许控制基本状态栏颜色。

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_height="match_parent"
        android:layout_width="match_parent" >
    
        <!-- `android:fitsSystemWindows="true"` moves `root_coordinatorlayout` below the system status bar.
         When it is specified, the theme should include `<item name="android:windowTranslucentStatus">true</item>`.
         `android:background` sets the background color of the status bar, which is then overlaid with a scrim. -->
        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/root_coordinatorlayout"
            xmlns:tools="http://schemas.android.com/tools"
            tools:context="com.my.acivity"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:fitsSystemWindows="true"
            android:background="#FF64DD17" >
    
            <!-- The purpose of the `LinearLayout` is to place the included `main_webview` below `app_bar_layout`. -->
            <LinearLayout
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:orientation="vertical" >
    
                <!-- The `AppBarLayout` theme has to be defined here because the activity uses a `NoActionBar` theme. -->
                <android.support.design.widget.AppBarLayout
                    android:id="@+id/app_bar_layout"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    android:theme="@style/AppBarLight" >
    
                    <android.support.v7.widget.Toolbar
                        android:id="@+id/app_bar"
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent" />
                </android.support.design.widget.AppBarLayout>
    
                <!-- Include the main views. -->
                <include layout="@layout/main_views" />
            </LinearLayout>
        </android.support.design.widget.CoordinatorLayout>
    
        <!-- The left drawer. -->
        <android.support.design.widget.NavigationView
            android:id="@+id/navigationview"
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:layout_gravity="start"
            app:headerLayout="@layout/navigation_header"
            app:menu="@menu/webview_navigation_menu"
            app:itemIconTint="?attr/navigationIconTintColor" />
    
        <!-- Include the right drawer. -->
        <include layout="@layout/right_drawer" />
    

    斯克里姆人 #FF64DD17 把它变暗 #FF3C850E .

    Green status bar

    #FF183405 .

    Navigation drawer open