繁体   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

有一个全屏活动,以下代码块用于实现相同的目的:

@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);
    }

但是,当显示自定义对话框或编辑文本获得焦点时,底部导航栏会变得可见并停留在周围。 官方文档说:

如果一个新的活动或对话框出现在前台,获得焦点并部分覆盖正在进行的活动,则被覆盖的活动失去焦点并进入暂停状态。 然后,系统对其调用 onPause() 。

当被覆盖的 Activity 返回到前台并重新获得焦点时,它会调用 onResume()。

但是当对话框失去焦点时不会调用onResume() (通过日志检查)。

还尝试在自定义对话框的 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);

添加上述代码后,当自定义对话框在前台时,导航栏会隐藏,但当它失去焦点时,导航栏会弹回到屏幕上。

还尝试使用样式设置全屏模式。 请参考以下相同。

<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>

edittext 也是如此。 Activity 以全屏模式启动,但一旦 edittext 获得焦点,底部导航栏就可见并停留在周围。

任何输入将不胜感激。

干杯!

试试这段代码。

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

暂无
暂无

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

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