gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:06:23 24 4
gpt4 key购买 nike

有一个全屏 Activity ,使用以下代码块实现相同的目的:

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

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

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.

When the covered activity returns to the foreground and regains focus, it calls 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()

关于android - 显示对话框后或 EditText 获得焦点时,隐藏的导航栏(带有主页、后退和概览按钮的底部栏)可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53794548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com