Android implements the method of modifying the background, font and icon color of the status bar
preface:
For Android development, the modification of the status bar is really unfriendly. There is no API to use, which is not as convenient as IOS. But the UI likes to only engage in IOS. There is no way. All kinds of turning source code and writing reflection. It really hurts
Demand scenario:
When the toolbar and status bar need to be white or light color (such as simple book), the status bar will not be visible because the light style theme, font and icon are white. If it is changed to black, it will be very harmonious
1、 Modify status bar color:
To change the color of the status bar, take a look at this article. Portal: it's actually very simple to realize the gradient effect of the status bar
Effect of portal:
The status bar realized by this method changes color and has no black background
The effects achieved by using full screen mode are as follows (QQ effect):
The black background is obvious
My mobile phone is Huawei, system 7.0
2、 Modify status bar font:
General tools:
Used in activity:
effect:
Problems:
1. The background color of statusbar has become the default color of colorprimarydark, but my configuration is white background (see the last for the specific configuration code)
Analysis reason:
Setsystemuivisibility() will refresh the property configuration of the view. Because statusbar uses the colorprimarydark property by default, the color will change back to the default color
At this point, the method of setting the background in step 1 will fail
Reason: when the incoming resid is the same, the background color will not be set again
terms of settlement:
Modified effect:
3、 Full code:
1.MvpConfig
2. In application
3.BaseActivity
4、 Supplement:
Below 6.0, the 5.0 native system cannot modify the font color. It uses a clever way to set it to translucent gray
Because the background of the statusbar view in the window is modified directly, and frgame depends on the activity, the status bar is not very applicable when the activity and fragment jump directly. For example, the activity is blue, the fragment needs to be white, and the fragment needs to modify the color of the status bar through the window. It's a little troublesome
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.