android - 内容在 api 21 及更高版本的软导航栏后面

标签 android android-layout material-design android-view windowinsets

已升级应用以使用 Material Design - Theme.AppCompat.Light.NoActionBarToolbar 而非 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>

如果选项<item name="android:windowDrawsSystemBarBackgrounds">false</item> - 底部内容可见,但 statusbar 变成全黑。我无法将颜色更改为 colorPrimaryDark(在我的例子中是绿色)

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

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

有什么建议吗?

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

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

更新:

按照@azizbekian 的建议,我已将 fragment 容器替换为 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>

屏幕布局:

<?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>

结果如下:

更新#2

Activity 布局:

<?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>

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

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

最佳答案

android:fitsSystemWindows="true" 应用于您的 Root View 。

参见 this post详细解释。

关于android - 内容在 api 21 及更高版本的软导航栏后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45634969/

相关文章:

android - 如何在设备中运行 android 应用程序?

android - 删除 Android EditText 上的左侧填充

android - 相对布局 : button pushes other button off screen

css - Polymer 1.0 我如何设计纸张输入 :disabled?

android - 如何在 Android 中创建圆形电话屏幕?

android - OpenGL ES 2.0 : Is there a workaround for missing texture access in vertex shader?

android - 有没有办法在多个嵌套的 RecyclerView 之间共享同一个 LayoutManager

angular - 如何移动垫扩展指示?

android - Material 设计 : Nav Drawer Width

java - ListView 显示所有项目减去最后一个