android 沉浸式状态栏的三种方法

 
  
 //状态栏 导航栏都沉浸
 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     Window window = getWindow();
     window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
             | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
     window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
             | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
             | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
     window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
     window.setStatusBarColor(Color.TRANSPARENT);
     window.setNavigationBarColor(Color.TRANSPARENT);
 }
//状态栏都沉浸,但是toolbar会向上移动
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     Window window = getWindow();
     window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
     );
     window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

             | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
     window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
     window.setStatusBarColor(Color.TRANSPARENT);
 }
 //修改状态栏颜色,完成沉浸式。 StatusBarCompat的类请查看 http://blog.csdn.net/michael1112/article/details/77739704
 StatusBarCompat.compat(this,Color.parseColor("#008000"));

你可能感兴趣的:(Android)