簡體   English   中英

android中完全隱藏導航欄(不僅僅是按鈕)

[英]Completely hiding navigation bar (not only buttons) in android

我正在使用來自最新 Android Studio(2021.2.1 補丁 2)的“導航抽屜活動”模板作為開始。

如何完全隱藏導航欄? 以下代碼僅隱藏按鈕,但導航欄的白色背景仍然存在。

View decorView = getWindow().getDecorView();
int uiOptions = SYSTEM_UI_FLAG_LAYOUT_STABLE
              | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

謝謝。

在活動的onCreate()中應用此代碼:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            if (window != null) {
                window.decorView.windowInsetsController!!.hide(WindowInsets.Type.statusBars())
                window.decorView.windowInsetsController!!.hide(
                    WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars()
                )
            }
        } else {
            val decorView = window.decorView
            val uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            decorView.systemUiVisibility = uiOptions
        }

java 版本:

WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
getWindow().getInsetsController().hide(WindowInsetsCompat.Type.systemBars());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM