内容落后于 api 21 及更高版本的软导航栏

vsv*_*nko 5 android android-layout android-view material-design windowinsets

已升级应用程序以使用 Material Design - Theme.AppCompat.Light.NoActionBar、Toolbar而不是ActionBar等。

并且有问题。在 API >= 21 的设备上,底部内容隐藏在软导航栏(见下图)下

已找到解决此问题的解决方案:

在values-v21/styles.xml

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
        ...
        <item name="colorPrimaryDark">@color/green</item>
        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
</styles>
Run Code Online (Sandbox Code Playgroud)

如果选项<item name="android:windowDrawsSystemBarBackgrounds">false</item>- 底部内容可见,但状态栏变为完全黑色。我无法将颜色更改为colorPrimaryDark(在我的情况下为绿色)

如果选项<item name="android:windowDrawsSystemBarBackgrounds">true</item>- 底部内容不可见,并且状态栏为绿色,正如预期的那样。

我想要状态栏颜色(绿色)和可见的底部内容.. 可能,问题在于工具栏。它是否将内容向下推?

有什么建议?

<item name="android:windowDrawsSystemBarBackgrounds">true</item>

<item name="android:windowDrawsSystemBarBackgrounds">false</item>

更新:

正如@azizbekian 所建议的,我已经将 Fragmet 的容器替换为 CoordinatorLayout(在 FrameLayout 之前)并应用android:fitsSystemWindows="true" 在这种情况下底部面板是可见的,但不是在底部......目标是将按钮保持在底部......

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_height="match_parent"
              android:layout_width="match_parent"
              android:orientation="vertical">
    <include
        layout="@layout/toolbar"/>

        <!-- The main content view -->
        <android.support.design.widget.CoordinatorLayout
                android:id="@+id/content"
            android:fitsSystemWindows="true"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

屏幕布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android">
    <FocusableScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/order_editor_layout"
        android:fillViewport="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                layout="@layout/o_e_content" 
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"/>
        </RelativeLayout>
    </FocusableScrollView>
    <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/oe_bottom_pane"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是结果:

更新#2

活动布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ActionBarTheme"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <!-- The main content view -->
        <FrameLayout
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

替换LinearLayour为CoordinatorLayout作为活动的根。作为内容的根元素,我保留了FrameLayout. 应用android:fitsSystemWindows="true"到CoordinatorLayout。这样,所有内容都略微向上移动,部分内容位于工具栏下方(您可以在下图中看到 - 顶部元素是带有 + 和 - 符号的圆圈。但在之前的图像中,顶部有文本。)关于底部元素(按钮面板) - 仍然位于导航栏下方,但也略微向上移动。我已经标记android:background="@color/red"为更容易识别该面板的位置。

看来,我们走在正确的道路上。我们只需要 - 解决问题 - 为什么内容移动到工具栏下方.. 如果 tolbar 将是顶部 ui 元素,按钮将可见..

azi*_*ian 2

应用于android:fitsSystemWindows="true"您的根视图。

请参阅这篇文章以获取详细说明。