Tip: Android does not fit into the immersive title bar after version 4.4, to use this requirement
Method One:
Step one: Define a tool class Viewcolor
Package Com.contentprovide.liuliu.music_play3;import Android.annotation.targetapi;import android.app.Activity; Import Android.os.build;import android.view.view;import android.view.viewgroup;import Android.view.WindowManager; Import android.widget.linearlayout;//Set the immersive title bar of the tool class public class Viewcolor {/** * generates a rectangle bar with the same size as the status bar * * @param activity requires Set activity * * @param color status bar color value * * @return status bar Rectangle Bar */private static View Createstatusview (Activity activit Y, int color) {//Get status bar height int resourceId = activity.getresources (). Getidentifier ("Status_bar_height", "dime N "," Android "); int statusbarheight = Activity.getresources (). Getdimensionpixelsize (ResourceId); Draw a rectangle with the same height as the status bar view Statusview = new view (activity); Linearlayout.layoutparams params = new Linearlayout.layoutparams (ViewGroup.LayoutParams.MATCH_PARENT, Statu Sbarheight); Statusview.setlayoutparams (params); Statusview.setbackgroundcolor (color);return statusview; /** * Set the status bar color * * @param activity required to set the activity * @param color status bar color value */@TargetApi (build.version_codes. Ice_cream_sandwich) public static void SetColor (activity activity, int color) {if (Build.VERSION.SDK_INT >= Build.version_codes. KITKAT) {//Set status bar Transparent Activity.getwindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATU S); Generate a status bar size rectangle View statusview = createstatusview (activity, color); Add Statusview to layout viewgroup Decorview = (viewgroup) Activity.getwindow (). Getdecorview (); Decorview.addview (Statusview); Set the parameters of the root layout viewgroup Rootview = (viewgroup) ((ViewGroup) Activity.findviewbyid (Android. r.id.content)). Getchildat (0); Rootview.setfitssystemwindows (TRUE); Rootview.setcliptopadding (TRUE); } }}
Step two: Add in the Oncreat () method in the Mainactivity class
Viewcolor.setcolor (This,getresources (). GetColor (r.color.main_red));//red background is the color that needs the status bar to change
Step three: Join the root node of the main layout file
Android:fitssystemwindows= "true"
http://blog.csdn.net/codekxx/article/details/58079960
Android Development set immersive title bar