[英]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.