当前位置:   article > 正文

flutter 修改状态栏的颜色_flutter设置application下label状态栏的背景颜色

flutter设置application下label状态栏的背景颜色
在flutter载体页面,修改flutter页面的状态栏背景颜色,这两个方法就可以实现:

 /**
     * 6.0级以上的沉浸式布局
     *
     */
    public static void fitSystemBar(Activity activity) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
            return;
        Window window = activity.getWindow();
        View decorView = window.getDecorView();
        //View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN--能够使得我们的页面布局延伸到状态栏之下,但不会隐藏状态栏。也就相当于状态栏是遮盖在布局之上的
        //View.SYSTEM_UI_FLAG_FULLSCREEN -- 能够使得我们的页面布局延伸到状态栏,但是会隐藏状态栏。
        //WindowManager.LayoutParams.FLAG_FULLSCREEN
        int systemUiVisibility = decorView.getSystemUiVisibility();
        decorView.setSystemUiVisibility(systemUiVisibility
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            WindowManager.LayoutParams lp = window.getAttributes();
            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            window.setAttributes(lp);
        }
//        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(Color.BLACK);  //修改这个颜色,看一下效果
    }

/**
 * 6.0及以上的状态栏色调
 * @param light    true:白底黑字,false:黑底白字
 */
public static void lightStatusBar(Activity activity, boolean light) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
        return;
    Window window = activity.getWindow();
    View decorView = window.getDecorView();
    int visibility = decorView.getSystemUiVisibility();
    if (light) {
        visibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    } else {
        visibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    }
    decorView.setSystemUiVisibility(visibility);
}

网上的还有其它方案,可以参考,

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/549370
推荐阅读
相关标签
  

闽ICP备14008679号