Full screen immersive transparent status bar style for Android UI experience

preface:

After Android 4.4, Google provides an immersive full screen experience. In the immersive full screen mode, the status bar and virtual keys are dynamically hidden, and applications can use the complete screen space to give users an immersive experience according to Google. After Android 5.0, Google put forward the concept of colorpalette, so that developers can set the color of the system area themselves, so as to unify the color style of the whole app and the color style of the system. *** Let's look at the expected results first:

First of all, it is now clear which part is the status bar and which part is the navigation bar

The status bar is as follows

The navigation bar is as follows

How?

1.) first, realize full screen

The first one: inherit topic specific topic

For Android API 19 and above, you can use the topics related to * * * *. Transparentdecor * * * with corresponding translucency effect. Theme.holo.noactionbar.transparentdecor and theme.holo.light.noactionbar.transparentdecor are newly added, so you need to create a values-v19 file folder and create styles file. Add the following code

The second way is to use code in the activity

For Android 4.4 and above, you can add the following code

Android 5.0 or above can also use the following code to achieve full screen

Full screen effect

It is not difficult to find that the position occupied by the status bar disappears and overlaps with the app layout. Next, solve this problem

2.) solve the status bar occupancy problem

First: add the following settings to the theme

Second: add the following code to the activity layout root directory

The third method: setting through Java code

Fitssystemwindows only works on systems with SDK > = 19, that is, systems higher than 4.4. This property can be set for any view. As long as this property is set, all padding properties of this view will become invalid. This property will take effect only when the transparent status bar or navigation bar is set,

If the status bar and navigation bar are set to be transparent, it is equivalent to automatically adding a paddingtop with a value equal to the height of the status bar and a paddingbottom with a value equal to the height of the navigation bar to the view. The effect is as follows

3.) set the background color for the status bar navigation bar

4.4 for the above, you can modify the background color of contentview or dynamically add a view to contentview

The function of dynamically obtaining statusbarheight is as follows

Get the navigationbarheight function dynamically as follows

After Android 5.0, Google provided a new API to update the background color of the status bar and navigation bar

In this way, the overall effect is realized

4.) post the overall java code implementation

Summary:

In order to make the display effect more obvious, the background color of the status bar is inconsistent with the color of the title bar. In actual development, we will generally set it to a unified color to visually feel that the whole page is more unified, so that users can really immerse themselves in the app.

The above is the full screen immersive transparent status bar effect of Android UI experience 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
分享
二维码
< <上一篇
下一篇>>