Android沉浸式状态栏

Android之沉浸式状态栏的实现
所谓沉浸式状态栏确切的说就是设置状态栏颜色与整体布局一致。一般情况下,状态栏的底色都为黑色,而沉浸式状态栏则是把状态栏设置为透明或者半透明,然后设置状态栏色值。


因为沉浸式状态栏是在Android4.4的时候出现的,所以只有4.4及以后的版本才能使用,也就是API19以后版本可以使用。

1 SystemBarTint  jar


2 SystemBarTint库

git地址:https://github.com/jgilfelt/SystemBarTint

3 着色开始

需要在每个布局添加
  android:clipToPadding="false"
  android:fitsSystemWindows="true"
如下面所示:

在BaseActivity传入封装代码就可以简单实现着色了

 private void stateColror(int color) {
        if (android.os.Build.VERSION.SDK_INT > 18) {
            Window window = getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // 创建状态栏的管理实例
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            // 激活状态栏设置
            tintManager.setStatusBarTintEnabled(true);
            // 激活导航栏设置
            tintManager.setNavigationBarTintEnabled(true);
            // 设置一个颜色给系统栏
            tintManager.setTintColor(color);
        }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值