已升级应用程序以使用Material Design- Theme.AppCompat.Light.NoActionBar ,工具栏而不是 ActionBar 等。
并有一个问题。
在APi> = 21的设备上,底部内容将隐藏在软导航栏(请参见下图)下
找到了解决此问题的解决方案:
在值中-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>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
更新:
正如建议的@azizbekian一样,我已将fragmets的容器替换为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>
结果如下:
UPDATE#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>
将
LinearLayour
替换为CoordinatorLayout
作为 Activity 的根。作为内容的根元素,我保留
FrameLayout
。将
android:fitsSystemWindows="true"
应用于CoordinatorLayout
。这样,所有内容都会稍微向上移动,一部分会放在工具栏下方(您可以在下面的图像中看到-顶部元素是带+和-的圆圈。但是在以前的图像上顶部是文本。)关于底部元素(按钮面板)-仍位于导航栏下方,但也略微向上移动。我已标记
android:background="@color/red"
以便于识别此面板的位置。似乎,我们走对了路。我们所需要的-解决问题-为什么内容移动到工具栏下方。如果tolbar将成为顶部ui,则按钮将可见。
最佳答案
将android:fitsSystemWindows="true"
应用于您的根 View 。
有关详细说明,请参见this post。