我目前正在通過Android培訓,因爲我試圖正確隱藏導航欄。在training documentation它指出:隱藏導航欄 - Android培訓
您可以隱藏在Android 4.0導航欄和使用 SYSTEM_UI_FLAG_HIDE_NAVIGATION標誌更高。這段代碼隱藏了 導航欄和狀態欄:
然後他們繼續提供代碼示例。
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
正如你可以看到它說,SYSTEM_UI_FLAG_FULLSCREEN
標誌僅4.1可用,但他們說的這個代碼塊是4.1。這不會導致應用程序崩潰嗎?如果我的代碼塊看起來更像:
View decorView = getWindow().getDecorView();
if (Build.VERSION.SDK_INT == 14 || Build.VERSION.SDK_INT == 15){
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(uiOptions);
} else if (Build.VERSION.SDK_INT >=16) {
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;如果你只想隱藏導航,這就是全部 – user2511882