public static void setWhiteStatusBar(Activity activity) {
try {
Class<?> c = Class.forName("android.view.View");
Field field = c.getField("SYSTEM_UI_FLAG_LIGHT_STATUS_BAR");//正常现实上方状态栏
int property = (Integer) field.get(c);//返回field中在c中的值,即SYSTEM_UI_FLAG_LIGHT_STATUS_BAR的指
activity.getWindow().getDecorView().setSystemUiVisibility(property);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
activity.getWindow().setNavigationBarColor(0xfff0f0f0);
View decorView = activity.getWindow().getDecorView();
int lightFlag = Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1 ? 0x4000 : 0x10;
decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | lightFlag);
try {
Method method = activity.getWindow().getClass().getMethod("setNavigationDividerEnable", new Class[] {boolean.class});
method.invoke(activity.getWindow(), new Object[]{true});
} catch (Exception e) {
}
}
} catch (Exception e) {
}
}
Android使用反射修改状态栏的颜色
最新推荐文章于 2024-05-11 21:58:45 发布
