• 沉浸式状态栏使用记录


    //状态栏类型
    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));
    }
    }
  • 相关阅读:
    java对对象或者map的属性进行排序
    java生成32的md5签名串
    mybatis检测mysql表是否存在
    eureka服务注册发现流程和核心参数
    概率分布之间的距离度量以及python实现(三)
    距离度量以及python实现(二)
    距离度量以及python实现(一)
    tensorflow 1.0 学习:用别人训练好的模型来进行图像分类
    tensorflow 1.0 学习:模型的保存与恢复(Saver)
    tensorflow 1.0 学习:参数和特征的提取
  • 原文地址:https://www.cnblogs.com/andy-songwei/p/8066161.html
Copyright © 2020-2023  润新知