Detailed explanation of setting and adaptation of Android status bar

Detailed explanation of setting and adaptation of Android status bar

Recently, I've seen a lot of problems about the status bar. I've summarized the settings of the mobile phone status bar in two directions: 1 > 5.0 and 2 > 5.0. What I'm talking about here is the custom toolbar. I've hidden the titlebar here

(1) About 5.0: first, we need to set it in style under the res file,

Here, why do I set apptheme.base instead of using apptheme directly? I inherit appcompatactivity. If you hide the titlebar directly, the program will report an error if you do not do this base processing. If you inherit an activity, it will not report an error. In order to handle higher version adaptation, you must inherit appcompatactivity. Therefore, when adapting systems below 5.0, We need to make a base to load style

This is the end of 5.0

(2) For versions above 5.0, we need to add a values-21 file under res, as shown in the figure below

The code placed in style is as follows:

The mobile phone will be loaded according to the system version of your mobile phone. The second style above 5. X will be loaded, and the corresponding style will be modified for different system versions

Of course, these two steps are enough for adaptation, but we may need to enter the status bar that cannot be displayed on different interfaces. At this time, we need to control and modify the code with code. I also post the code directly. The code depends on others

(1) Set these in the activity,

(2) Override a class statusbarmanager to modify it:

After doing this, you can customize your status bar,

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