Android使用反射修改状态栏的颜色

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kururunga/article/details/79973885
    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) {
        }
    }
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页