美文网首页
Android StatusBar(状态栏) 显示、隐藏、沉浸式

Android StatusBar(状态栏) 显示、隐藏、沉浸式

作者: QXH313 | 来源:发表于2018-10-24 15:28 被阅读0次

    一、StatusBar颜色修稿

    public static void setStatusBarColor(@NonNull Window window, @ColorInt int color, boolean colorIsLight) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

    window.setStatusBarColor(color);

        }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

    int systemUiVisibility = window.getDecorView().getSystemUiVisibility();

            if (colorIsLight) {

    window.getDecorView().setSystemUiVisibility(systemUiVisibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

            }else {

    window.getDecorView().setSystemUiVisibility(systemUiVisibility ^ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

            }

    }

    }

    调用:setStatusBarColor(getActivity().getWindow(), Color.WHITE, true)

    二、隐藏StatusBar(在Activity中的使用,Fragment中加上getActivity().即可)

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);

    三、显示StatusBar(在Activity中的使用,Fragment中加上getActivity().即可)

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

    四、设置沉浸式StatusBar

    public void setStatusBarTranslucent() {

    WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();

        localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);

    }

    相关文章

      网友评论

          本文标题:Android StatusBar(状态栏) 显示、隐藏、沉浸式

          本文链接:https://www.haomeiwen.com/subject/rucxtqtx.html