MainActivity.java
//去掉标题栏(activity继承自AppCompatActivity),为了显示ToolBar supportRequestWindowFeature(Window.FEATURE_NO_TITLE); //如果activity继承自Activity requestWindowFeature(Window.FEATURE_NO_TITLE); Window window = getWindow(); //强制显示状态栏 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //window负责系统bar的background绘制,绘制透明背景的系统bar window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏颜色 window.setStatusBarColor(Color.parseColor("#ffffff")); window.setStatusBarColor(Color.TRANSPARENT); //设置状态栏字体为黑色 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); //设置状态栏字体为白色 //window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);