1. 程式人生 > >Android 動態隱藏顯示導航欄,狀態欄

Android 動態隱藏顯示導航欄,狀態欄

sets tab mil repeat art gif ava hide sticky

Talk is cheap, show me the code.

--Linus Torvalds


Okay, here:

一、導航欄:

[java] view plain copy
  1. private void hideNavigationBar() {
  2. View decorView = getWindow().getDecorView();
  3. int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  4. | View.SYSTEM_UI_FLAG_FULLSCREEN;
  5. decorView.setSystemUiVisibility(uiOptions);
  6. }
  7. private void showNavigationBar() {
  8. View decorView = getWindow().getDecorView();
  9. int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
  10. decorView.setSystemUiVisibility(uiOptions);
  11. }

相關:

SYSTEM_UI_FLAG_VISIBLE——顯示狀態欄和導航欄

SYSTEM_UI_FLAG_LOW_PROFILE——此模式下,狀態欄的圖標可能是暗的

SYSTEM_UI_FLAG_HIDE_NAVIGATION——隱藏導航欄

SYSTEM_UI_FLAG_FULLSCREEN——全屏,隱藏狀態欄和導航欄

SYSTEM_UI_FLAG_LAYOUT_STABLE

SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN——全屏,隱藏導航欄,狀態欄浮在布局上。

SYSTEM_UI_FLAG_IMMERSIVE——沈浸式:半透明的狀態欄和導航欄

SYSTEM_UI_FLAG_IMMERSIVE_STICKY——粘性沈浸式


二、狀態欄:

[java] view plain copy
  1. private void setStatusBarVisible(boolean
    show) {
  2. if (show) {
  3. int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
  4. uiFlags |= 0x00001000;
  5. getWindow().getDecorView().setSystemUiVisibility(uiFlags);
  6. } else {
  7. int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  8. | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  9. | View.SYSTEM_UI_FLAG_FULLSCREEN;
  10. uiFlags |= 0x00001000;
  11. getWindow().getDecorView().setSystemUiVisibility(uiFlags);
  12. }
  13. }

三、導航欄和狀態欄

[java] view plain copy
  1. private void setSystemUIVisible(boolean show) {
  2. if (show) {
  3. int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
  4. uiFlags |= 0x00001000;
  5. getWindow().getDecorView().setSystemUiVisibility(uiFlags);
  6. } else {
  7. int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  8. | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  9. | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  10. | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  11. | View.SYSTEM_UI_FLAG_FULLSCREEN;
  12. uiFlags |= 0x00001000;
  13. getWindow().getDecorView().setSystemUiVisibility(uiFlags);
  14. }
  15. }

Android 動態隱藏顯示導航欄,狀態欄