/**
* 沉浸状态栏
*/
public void setStatusBar(boolean isChange,Activity mActivity) {
if (!isChange){
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// mActivity.getWindow().setStatusBarColor(mActivity.getResources().getColor(R.color.window_status_bar));
// 透明状态栏
Window window = mActivity.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);
}
}
/**
*将状态栏元素设置为深色(为了解决背景色是白色状态栏元素看不见问题)
*
*/
public boolean setDeepStatusBar(boolean isChange,Activity mActivity) {
if (!isChange){
return false;
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
// 透明状态栏
Window window = mActivity.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);
//设置状态栏文字颜色及图标为深色
mActivity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
return true;
}else {
return false;
}
}
完整工具类链接:https://download.csdn.net/download/yonghuming_jesse/11579248
另,附上博主自己的淘宝客项目下载码(可查淘宝商品优惠券,使用优惠券购物后可加微信客服返现,返现额度全网最高,客服微信android_jesse):