Explain the immersive status bar effect example in Android

Inadvertently learned about the immersive status bar and felt that the thief was pulling on the tall, so I just tried to understand it and had this article. Now let's learn what an immersive status bar is. The traditional mobile phone status bar presents a black bar, which is obviously different from the main interface of the mobile phone. In the same way, the visual width is sacrificed to a certain extent, and the interface area becomes smaller.

Starting from Android KitKat (Android 4.4), Google has provided our developers with a set of transparent system UI styles for the status bar and navigation bar. In this way, we don't have to face the black upper and lower columns every day as before. We can also adjust them to the same style as activity to form a complete theme, which is the same as the systems above ios7.0, The immersive status bar and the main interface color are harmonious, and the visual effect is more cool.

However, although it sounds like a very tall immersive effect, it actually seems to be full screen. In fact, this is a controversial point. Many people are obsessed with whether the immersive status bar expands the content displayed on the screen or just changes the color of the status bar and title bar. In fact, I prefer the latter. Before 4.4, the status bar was always black. In 4.4, the feature of windowtranslucentstatus was introduced. Therefore, the color of the status bar can be set, the visual effect can be realized, and the container part can be integrated with the status bar and title bar. More directly, the color of the status bar and Title bar can be changed according to the interface color The color of the title bar and the complete interface display should be the reason why the immersive status bar is popular.

Google did not give the concept of immersive status bar. Google only said immersive mode. However, the name of the immersive status bar is actually quite good and can only follow the public, but the Android environment is not as unified as the IOS environment. For example, the virtual buttons of Huawei ROM and Xiaomi ROM are completely different, and there are many Android versions, which involve version compatibility issues, which is not easy for all Android developers. This is particularly important in the development of immersive status bar. If you display the immersive status bar on the machine before 4.4, there are often some unexpected results.

Immersive means that the image of the app interface extends to the status bar, and the application itself immerses in the status bar. Therefore, if the third-party software does not allocate pictures to the status bar, it will naturally be black. The status bar at the top and the virtual keys below are hidden and drawn from the edge when necessary. Immersion mode. When this mode is enabled, the application interface will occupy the whole screen, and the system will automatically hide the status bar and navigation bar of the system, so that the application content can be presented in the maximum display range to increase the large screen experience. When you need to view the notification, you only need to slide down from the top to call out the notification bar.

In fact, there are two immersion modes: one is called "immersion mode". The status bar and virtual buttons will be automatically hidden and the application will be automatically full screen. In this mode, the application occupies all the space of the screen. The immersion mode will be exited only when the user swipes down from the upper edge of the screen. When the user touches other parts of the screen, he will not exit this mode, This model is more suitable for readers and magazines. The other is called "sticky immersion mode", which makes the status bar and virtual buttons translucent. The application uses all the space of the screen. When the user slides down from the upper edge of the screen, he will not exit this mode, but the system interface (status bar and navigation bar) will appear on the application view with a semi transparent effect, Only when the user clicks the control on the system interface will he exit the sticky immersion mode.

Let's talk about the specific implementation. In fact, there are many system elements on the interface of an Android application, including status bar, actionbar, navigation bar, etc. To create an immersive user experience is to integrate these system elements. When the main interface changes, the status bar, actionbar and navigation bar also change. 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's 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. This effect is not called immersive status bar, and there is no saying of immersive status bar at all, We can call it transparent status bar effect.

Hide status bar:

How to realize the specific immersion effect? The system provides a method to realize the immersion status bar through WindowManager, which can be divided into two steps:

1. Add the following parameters to the layout of the activity that needs to implement the immersive status bar

2. Just call the initialized method after the setcontentview () method of the activity.

When the above implementation effect is not good, and cliptopadding is not set to true in the layout, the top toolbar of the application will be stretched. After both parameters are set in the layout, the top status bar will turn white. In this way, I found a good immersion status bar effect on GitHub. Let's have a look.

First, add dependencies and import the following packages. Sometimes there may be a problem of inconsistent versions. When the Internet is connected in turn, click synchronize, and Android studio will automatically download the package.

compile 'com.jaeger.statusbaruitl:library:1.2.5'

The input logic implemented in the custom control has a long code.

The next step is to call the custom control, using two key methods. Statusbarutil.settransientforimageview (mainactivity. This, title) and lltitle.setbackgroundcolor (color. ARGB ((int) alpha, 227,29,26)) set the colors of the status bar and title bar respectively.

Last demo download: Demo

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>