This feature is supported by andorid 4.4, and it requires at least API19 to use. That is to say, if the Android machine is lower than 4.4, the immersion notification bar will have no effect. The following is a very simple way to use it.
/** * Set the notification bar This method is implemented in onCreate(). If it is added in the onCreate() of the parent class, even if all inherits the parent class, there will be an immersive notification bar. */ public void initSystemBar() { if (.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); SystemBarTintManager tintManager = new SystemBarTintManager(this); (true); (); } } /** * Set the status of the notification bar * @param on */ @SuppressLint("InlinedApi") private void setTranslucentStatus(boolean on) { Window win = (); winParams = (); final int bits = .FLAG_TRANSLUCENT_STATUS; if (on) { |= bits; } else { &= ~bits; } (winParams); }
In the end, add in the layout file: android:fitsSystemWindows="true"
It can be achieved.
Android 5.0 has a fully transparent status bar effect, and the specific example code is as follows:
The code to achieve the above effect is as follows:
public class MainActivity extends Activity { @SuppressLint("InlinedApi") @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); if(VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { Window window = getWindow(); (.FLAG_TRANSLUCENT_STATUS | .FLAG_TRANSLUCENT_NAVIGATION); ().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); (.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); (); (); } setContentView(.activity_main); } }
The above code is not well written, please give it to you all. I hope that sharing this article will be helpful to everyone.