android隱藏顯示狀態欄
㈠ Android 完全隱藏狀態欄方法
Android 完全隱藏狀態欄方法 https://blog.csdn.net/ljbphoebe/article/details/88179576
1. 隱藏ActionBar:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.hide();
}
如果是繼承AppCompatActivity,就用getSupportActionBar()。
2. 隱藏狀態欄
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
通過這兩個步就可以全屏顯示啟動頁了。
然而,當開始動態申請許可權,彈出系統的許可權提示對話框後,狀態欄又重新露出來了。我日,不是隱藏了嗎?怎麼又出來了,什麼鬼?
通過查看源碼的解釋:
/**
* Request that the visibility of the status bar or other screen/window
* decorations be changed.
*
* <p>This method is used to put the over device UI into temporary modes
* where the user's attention is focused more on the application content,
* by dimming or hiding surrounding system affordances. This is typically
* used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY
* Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content
* to be placed behind the action bar (and with these flags other system
* affordances) so that smooth transitions between hiding and showing them
* can be done.
*
* <p>Two representative examples of the use of system UI visibility is
* implementing a content browsing application (like a magazine reader)
* and a video playing application.
*
* <p>The first code shows a typical implementation of a View in a content
* browsing application. In this implementation, the application goes
* into a content-oriented mode by hiding the status bar and action bar,
* and putting the navigation elements into lights out mode. The user can
* then interact with content while in this mode. Such an application should
* provide an easy way for the user to toggle out of the mode (such as to
* check information in the status bar or access notifications). In the
* implementation here, this is done simply by tapping on the content.
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java
* content}
*
* <p>This second code sample shows a typical implementation of a View
* in a video playing application. In this situation, while the video is
* playing the application would like to go into a complete full-screen mode,
* to use as much of the display as possible for the video. When in this state
* the user can not interact with the application; the system intercepts
* touching on the screen to pop the UI out of full screen mode. See
* {@link #fitSystemWindows(Rect)} for a sample layout that goes with this code.
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java
* content}
*
* @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE},
* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN},
* {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION},
* {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}, {@link #SYSTEM_UI_FLAG_IMMERSIVE},
* and {@link #SYSTEM_UI_FLAG_IMMERSIVE_STICKY}.
*/
從釋義上可以知道,setSystemUiVisibility()是用於使系統UI進入一種臨時的模式,目的是使用戶的注意力關注於應用程序的內容上。所以單獨一個Activity這樣設置是可以全屏顯示的,這個只對當前的Activity有效。可是當申請系統許可權使,彈出的對話框是系統的Activity,通過adb shell mpsys activity 來看,當前最頂端的Activity已經是GrantPermissionsActivity。
Run #2: ActivityRecord{2b99111 u0 com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity t141}
而這個GrantPermissionsActivity,我們並無法去設置它的setSystemUiVisibility()。所以這種方法不奏效。
通過和同事討論,後來找到一種方法,可以實現我們的需求。
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
這種方法是OK的。
它的源碼釋義是:
/**
* Set the flags of the window, as per the
* {@link WindowManager.LayoutParams WindowManager.LayoutParams}
* flags.
*
* <p>Note that some flags must be set before the window decoration is
* created (by the first call to
* {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
* {@link #getDecorView()}:
* {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
* {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}. These
* will be set for you based on the {@link android.R.attr#windowIsFloating}
* attribute.
*
* @param flags The new window flags (see WindowManager.LayoutParams).
* @param mask Which of the window flag bits to modify.
* @see #addFlags
* @see #clearFlags
*/
public void setFlags(int flags, int mask) {}
仔細分析發現,這個是設置整個當前Window的,而setSystemUiVisibility()聚焦於顯示Activity內容的,還是有差別的。
/**
* Window flag: hide all screen decorations (such as the status bar) while
* this window is displayed. This allows the window to use the entire
* display space for itself -- the status bar will be hidden when
* an app window with this flag set is on the top layer. A fullscreen window
* will ignore a value of {@link #SOFT_INPUT_ADJUST_RESIZE} for the window's
* {@link #softInputMode} field; the window will stay fullscreen
* and will not resize.
*
* <p>This flag can be controlled in your theme through the
* {@link android.R.attr#windowFullscreen} attribute; this attribute
* is automatically set for you in the standard fullscreen themes
* such as {@link android.R.style#Theme_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Black_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Light_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Holo_NoActionBar_Fullscreen},
* {@link android.R.style#Theme_Holo_Light_NoActionBar_Fullscreen},
* {@link android.R.style#Theme_DeviceDefault_NoActionBar_Fullscreen}, and
* {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_Fullscreen}.</p>
*/
public static final int FLAG_FULLSCREEN = 0x00000400;
從釋義上得知,設置這個flag可以隱藏所有的屏幕修飾,像status bar,用於Window使用整個顯示屏。這個完全是我們的目的了。
㈡ Android去除狀態欄的方法匯總
一、隱藏標題欄
//隱藏標題欄
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
二、隱藏狀態欄
//隱藏狀態欄
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
三、去掉所有Activity界面的標題欄
修改AndroidManifest.xml
在application 標簽中添加android:theme="@android:style/Theme.NoTitleBar"
四、去掉所有Activity界面的TitleBar 和StatusBar
修改AndroidManifest.xml
在application 標簽中添加
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
㈢ 安卓手機隱藏狀態欄怎麼操作
方法:
1、進入手機「設置」界面,依次點擊「隱私權」→「恢復出廠設置」項
2、在彈出的「恢復出廠設置」窗口中點擊「重置手機」按鈕
3、接著點擊「備份數據」按鈕,對系統中的重要數據進行一次備份。
4、然後點擊「消除全部數據」按鈕。
5、此時手機會自動重啟,並進行數據的清除操作。
6、重啟完成後狀態欄又出現。
㈣ Android 顯示、隱藏狀態欄和導航欄
Android 顯示、隱藏狀態欄和導航欄
控制狀態欄顯示,Activity的主題中配置全屏屬性
控制狀態欄顯示,在setContentView之前設置全屏的flag
控制狀態欄顯示,在任何位置通過添加和移除全屏的flag
控制狀態欄和導航欄顯示,setSystemUiVisibility
// 全屏展示
// 非全屏顯示,顯示狀態欄和導航欄