问题描述
已升级应用程序以使用Material Design- Theme.AppCompat.Light.NoActionBar ,工具栏,而不是 ActionBar 等.
Have upgraded app to use Material Design - Theme.AppCompat.Light.NoActionBar, Toolbar instead of ActionBar etc..
有问题.在APi> = 21
And have a problem.Bottom content become to be hidden under soft NavigationBar (see picture below) on devices with APi >= 21
找到解决此问题的方法:
Have found solution to fix this:
在 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 (在我的情况下为绿色)
if option <item name="android:windowDrawsSystemBarBackgrounds">false</item>
- bottom content is visible, but statusbar become completely black. I cant change color to colorPrimaryDark (green in my case)
如果选项< item name ="android:windowDrawsSystemBarBackgrounds"> true</item>
-底部内容不可见,并且状态栏是预期的.
if option <item name="android:windowDrawsSystemBarBackgrounds">true</item>
- bottom content is invisible, and statusbar is green, as expected.
我希望状态栏为彩色(绿色)和可见的底部内容.工具栏可能是问题所在.它会压低内容吗?
I want to have statusbar colored(green) and visible bottom content..Probably, issue is with toolbar. Is it pushes content down?
有什么建议吗?
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
< item name ="android:windowDrawsSystemBarBackgrounds"> false</item>
更新:
正如建议的@azizbekian一样,我已将用于碎片的容器替换为CoordinatorLayout(在FrameLayout之前),并应用了 android:fitsSystemWindows ="true"
在这种情况下,底部面板可见,但底部不可见.目标是将按钮保持在底部...
As suggested @azizbekian, I've replaced container for fragmets to CoordinatorLayout(before FrameLayout) and applied android:fitsSystemWindows="true"
In this case bottom panel is visible, but not at the bottom..Goal is to keep buttons athe bottom...
<?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
活动布局:
<?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
作为活动的根.作为内容的根元素,我保留了 FrameLayout
.将 android:fitsSystemWindows ="true"
应用于 CoordinatorLayout
.这样,所有内容都会稍微向上移动,一部分会放在工具栏下方(您可以在下面的图像中看到-顶部元素是带+和-的圆圈.但是在以前的图像上顶部是文本.)关于底部元素(按钮面板)-仍位于导航栏下方,但也略微向上移动.我已标记 android:background ="@ color/red"
以便于识别此面板的位置.
Replaced LinearLayour
with CoordinatorLayout
as root for activity. As root element for content I've keep FrameLayout
.Applied android:fitsSystemWindows="true"
to CoordinatorLayout
.This way, all content was slightly moved up and part of placed below the toolbar(you can see on image below - top elements are circle with + and - symbold. But on previous images there are text on the top.) Regarding bottom elements (buttons panel) - still placed below navigation bar but also slightly moved up. I've marked android:background="@color/red"
to easier recognize position of this panel.
似乎,我们走对了路.我们所需要的-解决问题-为什么内容移动到工具栏下方.如果tolbar将成为顶部ui,则按钮将可见..
Seems, we are on the right way. All we need - to resolve problem - why content moved below the toolbar.. If tolbar will be top ui elemnt, buttons will be visible..
推荐答案
将 android:fitsSystemWindows ="true"
应用于根视图.
有关详细说明,请参见这篇文章.
See this post for detailed explanation.
这篇关于内容在api 21及更高版本的软导航栏后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!