Especially for video APPs, you need to switch to horizontal screen, hide the system status bar and display it in full screen to achieve videos with larger pictures. When switching back to the vertical screen, the status bar is displayed again. So how to achieve it?
There are many practices circulating on the Internet. for example:
1. Modify the theme in the file toandroid:theme=”@android:style/”
2. Execute the following code before the setContentView method:
requestWindowFeature(Window.FEATURE_NO_TITLE) getWindow().setFlags(.FLAG_FULLSCREEN,.FLAG_FULLSCREEN);
3. Through the setSystemUiVisibility method of View
4. The status bar is hidden and displayed through the following code:
getWindow().addFlags(.FLAG_FULLSCREEN) //Hide status bargetWindow().clearFlags(.FLAG_FULLSCREEN) //Show status bar
In my project, I want to implement the following requirements: In the current Activity, after switching to horizontal screen, the Activity cannot be destroyed and then re-initialized, and the system status bar is hidden and displayed in full screen; when switching back to vertical screen, the status bar is displayed again. Also, I don't need to hide the title bar.
Therefore, methods 1 and 2 are not suitable for me. Method 3, I have used, called the setSystemUiVisibility method, and the parameters passed in this method can be:
.SYSTEM_UI_FLAG_VISIBLE: Display the status bar, the Activity is not displayed in full screen (restored to the normal state of being in a state).
: Hide the status bar, and the Activity will be displayed in full screen.
.SYSTEM_UI_FLAG_FULLSCREEN: Activity is displayed in full screen, and the status bar is hidden and overwritten.
.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN: Activity is displayed in full screen, but the status bar will not be hidden and overwritten, the status bar is still visible, and the top layout part of the Activity will be blocked by the status.
.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION: The effect is the same as View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
.SYSTEM_UI_LAYOUT_FLAGS: The effect is the same as View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
.SYSTEM_UI_FLAG_HIDE_NAVIGATION: Hide virtual buttons (navigation bar). Some phones use virtual buttons instead of physical buttons.
.SYSTEM_UI_FLAG_LOW_PROFILE: The status bar display is in a low profile mode, and some icons on the status bar will be hidden.
What I need to pass in here isView.SYSTEM_UI_FLAG_FULLSCREEN
, but when I pass in this parameter, the result is: it just the status bar disappeared, but the location is still there. (Test phone: Huawei Honor 8 system is EMUI 5.0 based on Android 7.0; Samsung Galaxy s6 system is Android 6.0)
Finally, use method 4 to successfully meet the needs.
Summarize
The above is the hidden and display function of the Android implementation system status bar introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!