可全局变成黑白,纪念,灰色 不是及时改变 想要全局变成黑白app需要重新启动app
当然需要写在BaseActivity才能全局变成黑白
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
if ("FrameLayout".equals(name)) {
int count = attrs.getAttributeCount();
for (int i = 0; i < count; i++) {
String attributeName = attrs.getAttributeName(i);
String attributeValue = attrs.getAttributeValue(i);
if (attributeName.equals("id")) {
int id = Integer.parseInt(attributeValue.substring(1));
String idVal = getResources().getResourceName(id);
if ("android:id/content".equals(idVal)) {
//因为这是API23之后才能改变的,所以你的判断版本
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//获取窗口区域
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//设置状态栏颜色
window.setStatusBarColor(Color.parseColor("#848484"));
//设置显示为白色背景,黑色字体
// window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
GrayFrameLayout grayFrameLayout = new GrayFrameLayout(context, attrs);
return grayFrameLayout;
}
}
}
}
return super.onCreateView(name, context, attrs);
}