zoukankan      html  css  js  c++  java
  • 沉浸式状态栏使用记录

    //状态栏类型
    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));
    }
    }
  • 相关阅读:
    JQ优化性能
    CSS3 Filter的十种特效
    立即执行函数: (function ( ){...})( ) 与 (function ( ){...}( )) 有什么区别?
    EasyUI DateBox
    Java8接口的默认方法
    MySQL -- insert ignore语句
    建数据库表经验总结
    IntelliJ IDEA 实用快捷键
    从 Java 代码到 CPU 指令
    使用ImmutableMap简化语句
  • 原文地址:https://www.cnblogs.com/andy-songwei/p/8066161.html
Copyright © 2011-2022 走看看