Android immersive status bar and hidden navigation bar example explanation

1 Preface

Generally, in android app development, the app interface is as follows:

You can see that there are status bar, action bar (toolbar), navigation bar, etc. Generally speaking, there are three requirements for app to realize immersive: immersive status bar, hidden navigation bar and full screen app

Immersive status bar means that the color of the status bar matches that of the actionbar,

To hide the navigation bar, needless to say, is to hide the navigation bar and remove the black bar below.

App full screen refers to hiding the status bar and navigation bar. For example, many game interfaces are full screen app.

Therefore, when doing this step, the key is to ask the needs of product dogs, so as not to waste your efforts.

Next, we will introduce the implementation of these three methods.

2 immersive status bar

The general effect of immersive status bar is as follows:

There are many online schemes for immersive status bar, such as MD design of Android 5.0 or above, or modifying the setstatubarcolor() method of activity's window to set the color. When it is necessary to explain, the immersive status bar is only valid for api19 and above.

Here, I still use the method of setting the window of activity and setting setstatubarcolor(). The code is as follows:

3 hide navigation bar

The UI flag is used to hide the navigation bar

4 app full screen

The app full screen here is divided into hidden status bar and actionbar, and hidden navigation bar and status bar.

Hide status bar:

The effects are as follows:

Here we call the getWindow ().GetDecorView () method to get the DecorView of the current interface, then call its setsystemUIVisibility () method to set the visibility of the system UI element. System_ UI_ FLAG_ Fullscreen means full screen, that is, it will hide the status bar. In addition, according to Android design suggestions, the actionbar should not be displayed separately from the status bar. Therefore, if the status bar is hidden, we also need to call the hide() method of actionbar to hide the actionbar.

Hide navigation bar, status bar:

This interface is required for general games. The code is as follows:

In onwindowfocuschanged() of activity, set the interface to be full screen.

The effects are as follows:

You can see that the interface is full screen by default, and the status bar and navigation bar will not be displayed. When we need to use the status bar or navigation bar, we just need to pull down at the top of the screen or pull left at the right side of the screen, and the status bar and navigation bar will be displayed. At this time, the display or size of any element on the interface will not be affected. After a period of time, if there is no operation, the status bar and navigation bar will automatically hide and return to the full screen state.

Transparent status bar, navigation bar:

In addition, by setting the UI flag, you can make the navigation bar and status bar transparent.

The effects are as follows:

The above is a detailed explanation of the Android immersive status bar and hidden navigation bar introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>