• 沉浸式状态栏使用记录


    //状态栏类型
    public static final int STATUSBAR_TYPE_TRANSPARENT_WHITE = 1; //状态栏类型为透明底部,白色字体图标
    public static final int STATUSBAR_TYPE_WHITE_BLACK = 2; //状态栏类型为白色底部,黑色字体图标
    public static void setStatusBar(Activity pActivity, int pStatusbarType) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    //5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色
    Window window = pActivity.getWindow();
    View decorView = window.getDecorView();
    //两个 flag 要结合使用,表示让应用的主体内容占用系统状态栏的空间
    int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    if (pStatusbarType == STATUSBAR_TYPE_WHITE_BLACK) {
    option |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    }
    decorView.setSystemUiVisibility(option);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

    if (pStatusbarType == STATUSBAR_TYPE_WHITE_BLACK) {
    //背景
    window.setStatusBarColor(Color.WHITE);
    } else if (pStatusbarType == STATUSBAR_TYPE_TRANSPARENT_WHITE) {
    //背景
    window.setStatusBarColor(Color.TRANSPARENT);
    }
    //底部导航栏颜色
    // window.setNavigationBarColor(Color.TRANSPARENT);
    // window.setNavigationBarColor(ContextCompat.getColor(activity, R.color.black));
    } else {
    //以下这种情况没有测试过
    /* if (pStatusbarType == UtilsKey.STATUSBAR_TYPE_WHITE_BLACK) {
    setStatusBar2(pActivity);
    } else if (pStatusbarType == UtilsKey.STATUSBAR_TYPE_TRANSPARENT_WHITE) {*/
    Window window = pActivity.getWindow();
    WindowManager.LayoutParams attributes = window.getAttributes();
    int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    attributes.flags |= flagTranslucentStatus;
    /*int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
    attributes.flags |= flagTranslucentNavigation;*/
    window.setAttributes(attributes);
    // }
    }
    }
    }

    public static void setStatusBar2(Activity pActivity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    pActivity.getWindow().getDecorView().setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    pActivity.getWindow().setStatusBarColor(Color.WHITE);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    pActivity.getWindow().setStatusBarColor(ContextCompat.getColor(pActivity, R.color.translucent));
    }
    pActivity.getWindow().setNavigationBarColor(ContextCompat.getColor(pActivity, R.color.black));
    }
    }
  • 相关阅读:
    2015-05-06前端开发总结
    深入了解 Flexbox 伸缩盒模型
    Sublime text3 快捷方式(windows平台)
    移动web最简洁的滑动效果Swipe JS(适合初学者)
    谈响应式web设计代码实现
    经验分享:多屏复杂动画CSS技巧三则
    css3 animation动画效果解析
    移动H5前端性能优化指南
    php codeigniter (CI) oracle 数据库配置-宋正河整理
    jquery图片裁切+PHP文件上传
  • 原文地址:https://www.cnblogs.com/andy-songwei/p/8066161.html
Copyright © 2020-2023  润新知