Android沉浸式状态栏

Android沉浸式状态栏

市场上,现阶段很流行Android沉浸式开发,但是限于google api的限制,所以此特性只能针对Android4.4,Github上目前开源的SystemBarTint能够很好的实现此特性。

沉浸式实现

Android 4.4 特有属性,Android 5.0以上机型,默认开启。

1:利用Android studio 导入 jar 包

dependencies {
   compile     'com.readystatesoftware.systembartint:systembartint:1.0.3'
}

2:使用SytemBarTintManager

protected void setSystemBarTintDrawable(Drawable d) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            SystemBarTintManager mTintManager = new SystemBarTintManager(this);
            if (d != null) {
      mTintManager.setStatusBarTintEnabled(true);
                mTintManager.setTintDrawable(d);
            } else {
      mTintManager.setStatusBarTintEnabled(false);
                mTintManager.setTintDrawable(null);
            }
       }
 }

3:设置状态栏透明

  /**
     * set status bar translucency
     *
     * @param on
     */
    protected void setTranslucentStatus(boolean on) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window win = getWindow();
            WindowManager.LayoutParams winParams = win.getAttributes();
            final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
            if (on) {
                winParams.flags |= bits;
            } else {
                winParams.flags &= ~bits;
            }
            win.setAttributes(winParams);
        }
    }

4:设置完成
5:温馨提示:[DEPRECATED] Apply background tinting to the Android system UI when using KitKat translucent modes 。SystemBarTint上已经不支持使用该jar了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值