android 如何在不重叠导航栏的情况下获得系统栏色调?

How to get systembar tint without overlapping navigation bar in android?

这是我当前的 XML,我用它得到了上面的输出。如何在不重叠抽屉的情况下获得色调效果?

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    >        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:fitsSystemWindows="true"
            android:weightSum="1">

            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar"
               />
        </LinearLayout>
        <com.heinrichreimersoftware.materialdrawer.DrawerView
            android:id="@+id/drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"/>
    </android.support.v4.widget.DrawerLayout>

我正在使用 ready state softwares 的 Systembar 色调库来获取 kitkat 上的半透明状态栏。

也许这可以帮助你:

将所有内容放在 android:fitsSystemWindows="true":

的 RelativeLayout 中
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.v4.widget.DrawerLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="1">

            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar" />

        </LinearLayout>

        <com.heinrichreimersoftware.materialdrawer.DrawerView
            android:id="@+id/drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"/>

    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

EDIT/CREATE 样式资源

/values/styles.xml:

    <resources>

    <style name="AppTheme" parent="AppTheme.Base"/>

    <style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorPrimary">@color/primary</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:windowBackground">@color/primary_dark</item>
    </style>

</resources>

/values-v19/styles.xml:(对于奇巧)

<resources>

    <style name="AppTheme" parent="AppTheme.Base">
        <item name="android:windowTranslucentStatus">true</item>
    </style>

</resources>

/values-v21/styles.xml:(棒棒糖)

<resources>

    <style name="AppTheme" parent="AppTheme.Base"/>
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorAccent">@color/accent</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

</resources>

将此添加到您的主题中,这将使您的工具栏透明

<item name="android:windowBackground">@android:color/transparent</item>

将此添加到您的颜色中 xml 以获得透明颜色

<color name="transparent">#00000000</color>