Home >Java >javaTutorial >Android implements immersive notification bar. The background color of the notification bar changes according to the background color of the app navigation bar.

Android implements immersive notification bar. The background color of the notification bar changes according to the background color of the app navigation bar.

高洛峰
高洛峰Original
2017-01-20 15:48:031906browse

Recently, many apps have satisfied the immersive notification bar. The so-called immersive notification bar: It hides the various interface operation spaces used for navigation in a scenario dominated by program content, through a relatively "invisible" interface. To maximize the user's visibility to the content itself.

The notification bar immersion mode of the latest Android 4.4 system is that when the software is opened, the notification bar and the top color of the software are integrated. This not only makes the software and the system itself more integrated. The color of the notification bar of the mobile phone is no longer just white or black. The Xiaomi Mi 4 mobile phone I use, the built-in software of the Mi 4 mobile phone supports the immersive notification bar. For example: you can take a look at your own QQ, the background color of its title is blue, then the notification bar will also turn blue. It may not have been possible before, but it has been supported recently.

I don’t know when miui6 will be supported uniformly. Let me tell you how to make your app support the immersive notification bar:

There are experts on github who have researched it. Let’s talk about how to achieve it:

First download SystemBarTint and convert it inside Copy SystemBarTintManager.java and put it into your own project. Judge and set the color of the notification bar in the onCreate() method of activity (the color needs to be defined according to the background of the titlebar of the software)

Code 1 :

The code is as follows:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.statusbar_bg);//通知栏所需颜色

The following is to set the status of the notification bar

@TargetApi(19)
private void setTranslucentStatus(boolean on) {
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (on) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
}

This way you can achieve perfect immersion Notification bar. Note that the system must be above 4.4. Friends, come and give it a try.

Code 2:

The background color of the notification bar (notification) changes according to the background color of the app navigation bar (top title).
This is also called the immersive status bar, which was proposed by Google in Android 4.4 and above.
The style is as shown in the figure:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

Then add in the xml layout file:

android:clipToPadding="false"
android:fitsSystemWindows="true"

More Android implementations of immersive notification bar notification bar background color follow For related articles about changing the background color of the app navigation bar, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn