This article introduces the Android immersive status bar and shares it with you. I hope it will be helpful to you.
1. Overview
Many mainstream App design styles now use Material Design. Today we will simply implement the effects of changing the color of the status bar and making the status bar transparent.
2. Implement the status bar color setting
Let's write a tool class StatusBarUtils
The code is as follows:
/** * Set the status bar color * * @param activity */ public static void setStatusColor(Activity activity, int color) { if (.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { // Directly call the method provided by the system setStatusBarColor ().setStatusBarColor(color); } else if (.SDK_INT > Build.VERSION_CODES.KITKAT) { // Between 4.4 - 5.0 Use a technique, first make it into full screen, add a layout to the status bar ().addFlags(.FLAG_FULLSCREEN); View view = new View(activity); params = new (.MATCH_PARENT, getStatusbarHeight(activity)); (params); (color); ViewGroup viewGroup = (ViewGroup) ().getDecorView(); (view); // Get the root layout of the setContentView layout in the activity ViewGroup contentView = (ViewGroup) (); View activityView = (0); (true); } } private static int getStatusbarHeight(Activity activity) { Resources resources = (); int statusHeightId = ("status_bar_height", "dimen", "android"); return (statusHeightId); }
Directly call the system-provided method setStatusBarColor between 4.4-5.0 and above, first make it into full screen, and then add a layout to the status bar.
3. Set the status bar to be transparent
Code:
public static void setActivityTranslucent(Activity activity) { if (.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { ().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); ().setStatusBarColor(); } else if (.SDK_INT > Build.VERSION_CODES.KITKAT) { ().addFlags(.FLAG_TRANSLUCENT_STATUS); } }
There is only so much code. After the analysis is completed, you can try the effect yourself. I won’t go to the picture now.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.