简体   繁体   English

显示对话框后或 EditText 获得焦点时,隐藏的导航栏(带有主页、后退和概览按钮的底部栏)可见

[英]Hidden Navigation bar (bottom bar with Home, Back and Overview button) is visible after showing a dialog or if the EditText gains focus

There is a full screen activity with the following code blocks used to achieve the same:有一个全屏活动,以下代码块用于实现相同的目的:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);

// ….
}

@Override
    protected void onResume() {
        Log.i(TAG, "onResume");

        super.onResume();
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                        // Set the content to appear under the system bars so that the
                        // content doesn't resize when the system bars hide and show.
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        // Hide the nav bar and status bar
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }

However, when a custom dialog is shown or if the edittext gains focus, the bottom navigation bar becomes visible and sticks around.但是,当显示自定义对话框或编辑文本获得焦点时,底部导航栏会变得可见并停留在周围。 The official doc says:官方文档说:

If a new activity or dialog appears in the foreground, taking focus and partially covering the activity in progress, the covered activity loses focus and enters the Paused state.如果一个新的活动或对话框出现在前台,获得焦点并部分覆盖正在进行的活动,则被覆盖的活动失去焦点并进入暂停状态。 Then, the system calls onPause() on it.然后,系统对其调用 onPause() 。

When the covered activity returns to the foreground and regains focus, it calls onResume().当被覆盖的 Activity 返回到前台并重新获得焦点时,它会调用 onResume()。

But onResume() is not invoked when the dialog looses focus (checked with logs).但是当对话框失去焦点时不会调用onResume() (通过日志检查)。

Also tried adding the following code in onCreate() of custom dialog:还尝试在自定义对话框的 onCreate() 中添加以下代码:

View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                        // Set the content to appear under the system bars so that the
                        // content doesn't resize when the system bars hide and show.
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        // Hide the nav bar and status bar
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN);

After adding the above code, the navigation bar hides when the custom dialog is in foreground, but when it goes out of focus, the navigation bar pops back onto the screen.添加上述代码后,当自定义对话框在前台时,导航栏会隐藏,但当它失去焦点时,导航栏会弹回到屏幕上。

Also tried setting fullscreen mode using styles.还尝试使用样式设置全屏模式。 Please refer below the same.请参考以下相同。

<style name="FullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:windowContentTransitions">true</item>
</style>

Same is the case with edittext. edittext 也是如此。 Activity starts up in fullscreen mode, but as soon as edittext gains focus, the bottom navigation bar is visible and sticks around. Activity 以全屏模式启动,但一旦 edittext 获得焦点,底部导航栏就可见并停留在周围。

Any input would be appreciated.任何输入将不胜感激。

Cheers!干杯!

Try this code.试试这段代码。

fun View.setImmersiveMode() {
    isFocusableInTouchMode = false
    setOnClickListener {
        requestFocusFromTouch()
    }
}
editText.setImmersiveMode()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM