Tencent / QMUI_Android

提高 Android UI 开发效率的 UI 库
http://qmuiteam.com/android
Other
14.4k stars 2.67k forks source link

Flyme8 状态栏问题 #710

Closed Theoneee closed 4 years ago

Theoneee commented 4 years ago

QQ图片20190924111459 刚刚升级了Flyme8. 然后状态栏就直接有了一层遮罩。设置了QMUIStatusBarHelper.setStatusBarLightMode(this);也无效。好像其他应用也会,但是QQ没有出现(白色的背景情况)。这是适配的问题嘛。。

cgspine commented 4 years ago

image 魅族会默认走 FLAG_TRANSLUCENT_STATUS 的逻辑,可以帮忙测试下,是否魅族也可以走下边官方的沉浸式逻辑了?

Theoneee commented 4 years ago

@cgspine 可以加一个大佬的联系方式嘛。哈哈 或者大佬愿意的话加一下我。 Q 625805189

Theoneee commented 4 years ago

image 使用QMUIStatusBarHelper.translucent(this); 注释掉上面的。然后就走了下面那个地方。

Theoneee commented 4 years ago

现在的Flyme8好像走了官方的。然后不会像以前那样如果状态栏是白色的就会自动的转变成深色的图标。

Theoneee commented 4 years ago

大佬。有什么办法能够知道Fragment的父容器是ViewPager嘛。

Theoneee commented 4 years ago

image

这里把对Flyme的判断删除了。

然后我在BaseFragment里这样写的:

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if(onAnimationEndInit()){
            if (isStatusBarLightMode()) {
                QMUIStatusBarHelper.translucent(getBaseFragmentActivity());
                QMUIStatusBarHelper.setStatusBarLightMode(getBaseFragmentActivity());
            } else {
                QMUIStatusBarHelper.translucent(getBaseFragmentActivity(),getColorr(R.color.qmui_config_color_transparent));
                QMUIStatusBarHelper.setStatusBarDarkMode(getBaseFragmentActivity());
            }
        }
        getLazyViewLifecycleOwner().getLifecycle().addObserver(this);
    }

onAnimationEndInit() 是用来判断是否是ViewPager包裹的Fragment,因为这一类都有父Fragment包裹不让这类Fragment参与改变状态栏。

isStatusBarLightMode()默认是返回的是判断TopBar的背景颜色是否为白色或者有渐变色背景设置,

    protected boolean isStatusBarLightMode() {
        return !StatusBarUtil.isTranslucent(getBaseFragmentActivity());
    }
    public static boolean isTranslucent(Context context){
        Drawable bgDrawable;
        int bgColor;
        try {
            TypedArray array = context.obtainStyledAttributes(null, R.styleable.QMUITopBar, R.attr.QMUITopBarStyle, 0);
            bgColor = array.getColor(R.styleable.QMUITopBar_qmui_topbar_bg_color, Color.WHITE);
            bgDrawable = QMUIResHelper.getAttrDrawable(context, R.attr.qmui_topbar_bg_drawable);
            array.recycle();
        }catch (Exception e){
            bgDrawable = null;
            bgColor = Color.WHITE;
        }
       return null !=bgDrawable || bgColor!= Color.WHITE;
    }

这个方法也用来判断是否将遮罩设置为透明的,以此满足对5.x机型在非白色背景时可以去除掉遮罩。测试了一下,这样基本上都能满足需求了。在flyme低于8的机型测试也没问题。

这样写是默认全局的,当然某些界面不会按照此逻辑来,所以当有不同全局时,子类重写按照当时需求返回就可以了。

cgspine commented 4 years ago

Fragment onCreateView 三参数的第二个参数是container,我觉得可以根据它来判断父view的类型。

Theoneee commented 4 years ago

Fragment onCreateView 三参数的第二个参数是container,我觉得可以根据它来判断父view的类型。

赞赞赞~~