一、StatusBar颜色修稿
public static void setStatusBarColor(@NonNull Window window, @ColorInt int color, boolean colorIsLight) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(color);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
if (colorIsLight) {
window.getDecorView().setSystemUiVisibility(systemUiVisibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}else {
window.getDecorView().setSystemUiVisibility(systemUiVisibility ^ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
}
调用:setStatusBarColor(getActivity().getWindow(), Color.WHITE, true)
二、隐藏StatusBar(在Activity中的使用,Fragment中加上getActivity().即可)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
三、显示StatusBar(在Activity中的使用,Fragment中加上getActivity().即可)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
四、设置沉浸式StatusBar
public void setStatusBarTranslucent() {
WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
}
网友评论