已经升级应用程序以使用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>
如果选项
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
- 底部内容可见,但状态栏会变成完全黑色。我无法将颜色更改为colorPrimaryDark(在我的情况下是绿色)。如果选项
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
- 底部内容不可见,并且状态栏是绿色的,如预期。我想要有一个颜色(绿色)的状态栏和可见的底部内容...可能与工具栏有关。它是否向下推内容?
有什么建议吗?
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
![](https://istack.dev59.com/AeoR2.webp)
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
![](https://istack.dev59.com/g0FXR.webp)
如@azizbekian建议的那样,我将片段容器替换为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
活动布局:
<?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>
替换了根活动的
LinearLayout
为CoordinatorLayout
。
将FrameLayout
作为内容的根元素。
将android:fitsSystemWindows =“true”
应用于CoordinatorLayout
。
这样,所有内容都被轻微地向上移动,并且部分内容位于工具栏下方(您可以在下面的图片中看到 - 顶部元素是带有+和-符号的圆形。但是在以前的图片中,顶部有文本。)关于底部元素(按钮面板) - 仍然位于导航栏下方,但也略微向上移动。我已经标记了android:background =“@color/red”
以更容易地识别此面板的位置。
看起来我们走在正确的路上。我们需要解决的问题是为什么内容移到了工具栏下面...如果工具栏成为顶部UI元素,那么按钮就会可见..