使用SYSTEM_UI_FLAG_HIDE_NAVIGATION后,requestLayout无法反映更改 [英] requestLayout doesn't reflect the change after using SYSTEM_UI_FLAG_HIDE_NAVIGATION

查看:598
本文介绍了使用SYSTEM_UI_FLAG_HIDE_NAVIGATION后,requestLayout无法反映更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码/标志来隐藏底部的导航栏,但问题是我的活动视图本身不会重绘/刷新/重新布局以反映此更改.

I'm using the following code / flags to hide the bottom navigation bar, but the problem is that my activity views doesn't redraw / refresh / re-layout itself to reflect this change.

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
   int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
   View decorView = getWindow().getDecorView();
   decorView.setSystemUiVisibility(uiOptions);
}

RootRelativeLayout.requestLayout();

我的活动代码

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_relativelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:clipToPadding="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

    </RelativeLayout>

</RelativeLayout>

即使我在父级RelativeLayout上调用requestLayout(),内部的RelativeLayout仍会保留在其位置,就好像导航栏仍然存在并且不会掉到屏幕底部一样.

The inner RelativeLayout stays in its place as if the navigation bar still exist and don't drop to the bottom of the screen even though I called requestLayout() on its parent RelativeLayout.

如您在图片中看到的,底部有一个缺口

As you see in the picture there's a gab at the bottom

我找到了解决此问题的方法,但它也引起了另一个问题.

I found a solution to this problem but it also cause another problem.

我遇到的解决方案是将android:fitsSystemWindows设置为false而不是true.

The solution I came to is to set android:fitsSystemWindows to be false instead of true.

但这会导致一个问题,我的活动的顶部对齐视图位于状态栏后面,我唯一的解决方案是将顶部填充设置为状态栏的高度.

But it causes a problem, that my activity's aligned-top views go behind the status bar, the only solution in my mind is to set top padding to the height of the status bar.

推荐答案

对于将来的搜索者,解决方案是将fitsSystemWindows设置为false.

For future searchers the solution is to set fitsSystemWindows to be false.

android:fitsSystemWindows="false"

这篇关于使用SYSTEM_UI_FLAG_HIDE_NAVIGATION后,requestLayout无法反映更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆