laobie / StatusBarUtil

A util for setting status bar style on Android App.
http://t.cn/Rq746Kb
Apache License 2.0
8.81k stars 1.72k forks source link

关于toolbar陷入到状态栏问题 #279

Open CK875430315 opened 4 years ago

CK875430315 commented 4 years ago

setDarkMode和Slidr.attach(this) 结合好像不会出现,但是不配合就会有问题,如果不想侧滑退出只有加上android:fitsSystemWindows="true",怀疑Slidr这个库里加上了

vodLee commented 4 years ago

是不是setDarkModesetSystemUiVisibility这个地方的问题,这地方直接强制全屏了

guobinAndroid commented 4 years ago

是不是setDarkModesetSystemUiVisibility这个地方的问题,这地方直接强制全屏了

这个要怎么改?

vodLee commented 4 years ago

是不是setDarkModesetSystemUiVisibility这个地方的问题,这地方直接强制全屏了

这个要怎么改?

` @TargetApi(Build.VERSION_CODES.M) public static void setLightMode(Activity activity) { setMIUIStatusBarDarkIcon(activity, true); setMeizuStatusBarDarkIcon(activity, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } }

@TargetApi(Build.VERSION_CODES.M)
public static void setDarkMode(Activity activity) {
    setMIUIStatusBarDarkIcon(activity, false);
    setMeizuStatusBarDarkIcon(activity, false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
}

`

我遇到的问题是 util 的源代码中直接set导致,所以先vis = getSystemUiVisibility(),然后setSystemUiVisibility (vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR),当时大概是这么写的,demo找不到了。

思路的话当时看 setDarkModesetLightMode 的差距,在 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 这个常量上,看源码这个常量是只有一位是1的整形,盲猜底层是靠位运算去判断的。

所以这个地方先通过 get 方法获取原 activity 的 SystemUi,通过位运算去设置View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 对应的值,然后再通过set方法设置到 activity 的 SystemUi 上,解决了我当时的问题

vodLee commented 4 years ago

是不是setDarkModesetSystemUiVisibility这个地方的问题,这地方直接强制全屏了

这个要怎么改?

` @TargetApi(Build.VERSION_CODES.M) public static void setLightMode(Activity activity) { setMIUIStatusBarDarkIcon(activity, true); setMeizuStatusBarDarkIcon(activity, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } }

@TargetApi(Build.VERSION_CODES.M)
public static void setDarkMode(Activity activity) {
    setMIUIStatusBarDarkIcon(activity, false);
    setMeizuStatusBarDarkIcon(activity, false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
}

`

我遇到的问题是 util 的源代码中直接set导致,所以先vis = getSystemUiVisibility(),然后setSystemUiVisibility (vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR),当时大概是这么写的,demo找不到了。

思路的话当时看 setDarkModesetLightMode 的差距,在 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 这个常量上,看源码这个常量是只有一位是1的整形,盲猜底层是靠位运算去判断的。

所以这个地方先通过 get 方法获取原 activity 的 SystemUi,通过位运算去设置View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 对应的值,然后再通过set方法设置到 activity 的 SystemUi 上,解决了我当时的问题

刚才找到了以前的代码

@TargetApi(Build.VERSION_CODES.M)
public static void setLightMode(Activity activity) {
setMIUIStatusBarDarkIcon(activity, true);
setMeizuStatusBarDarkIcon(activity, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int visibility = activity.getWindow().getDecorView().getSystemUiVisibility();
if (visibility != (visibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)) {
visibility = visibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
}
}
@TargetApi(Build.VERSION_CODES.M)
public static void setDarkMode(Activity activity) {
    setMIUIStatusBarDarkIcon(activity, false);
    setMeizuStatusBarDarkIcon(activity, false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int visibility = activity.getWindow().getDecorView().getSystemUiVisibility();
        if (visibility == (visibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)) {
            visibility = visibility ^ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
    }
}
guobinAndroid commented 4 years ago

是不是setDarkModesetSystemUiVisibility这个地方的问题,这地方直接强制全屏了

这个要怎么改?

` @TargetApi(Build.VERSION_CODES.M) public static void setLightMode(Activity activity) { setMIUIStatusBarDarkIcon(activity, true); setMeizuStatusBarDarkIcon(activity, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } }

@TargetApi(Build.VERSION_CODES.M)
public static void setDarkMode(Activity activity) {
    setMIUIStatusBarDarkIcon(activity, false);
    setMeizuStatusBarDarkIcon(activity, false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
}

我遇到的问题是 util 的源代码中直接set导致,所以先vis = getSystemUiVisibility(),然后setSystemUiVisibility (vis & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR),当时大概是这么写的,demo找不到了。 思路的话当时看setDarkModesetLightMode的差距,在View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR这个常量上,看源码这个常量是只有一位是1的整形,盲猜底层是靠位运算去判断的。 所以这个地方先通过 get 方法获取原 activity 的 SystemUi,通过位运算去设置View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR` 对应的值,然后再通过set方法设置到 activity 的 SystemUi 上,解决了我当时的问题

刚才找到了以前的代码

@TargetApi(Build.VERSION_CODES.M)
public static void setLightMode(Activity activity) {
setMIUIStatusBarDarkIcon(activity, true);
setMeizuStatusBarDarkIcon(activity, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int visibility = activity.getWindow().getDecorView().getSystemUiVisibility();
if (visibility != (visibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)) {
visibility = visibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
}
}
@TargetApi(Build.VERSION_CODES.M)
public static void setDarkMode(Activity activity) {
    setMIUIStatusBarDarkIcon(activity, false);
    setMeizuStatusBarDarkIcon(activity, false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int visibility = activity.getWindow().getDecorView().getSystemUiVisibility();
        if (visibility == (visibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)) {
            visibility = visibility ^ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
    }
}

谢谢哈,我已经解决了。