沉浸式状态栏实现-SystemBarTint

1 SystemBarTint库

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

2 简介

在Android KitKat的translucent模式下,可以应用背景着色到Android的系统UI中。Android4.4(API19)介绍了透明的系统UI样式(状态status栏和导航条navigation bar),这些样式对于基于activity的墙纸应用是非常有用的,比如主屏的launcher.
该库提供了使用颜色值或drawable为系统bar创建背景着色的简单方式。

3使用

首先使activity的透明可用,有两种方式:
1) 使用*.TranslucentDecor或其子类主题
2) 通过设置android:windowTranslucentNavigation 或android:windowTranslucentStatus主题属性为true。
3) 在activity代码中添加标识FLAG_TRANSLUCENT_NAVIGATION 或FLAG_TRANSLUCENT_STATUS:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

在api 19以前的版本半透明translucency是不可用的,系统UI会正常出现。当使用全屏或沉浸式窗口模式时,着色tinting应该不可用。在API 10 及以上都可以安全的使用该库。
使tint可用

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // create our manager instance after the content view is set
    SystemBarTintManager tintManager = new SystemBarTintManager(this);
    // enable status bar tint
    tintManager.setStatusBarTintEnabled(true);
    // enable navigation bar tint
    tintManager.setNavigationBarTintEnabled(true);
}

提供定制的着色颜色值或drawable

// set a custom tint color for all system bars
tintManager.setTintColor(Color.parseColor("#99000FF"));
// set a custom navigation bar resource
tintManager.setNavigationBarTintResource(R.drawable.my_tint);
// set a custom status bar drawable
tintManager.setStatusBarTintDrawable(MyDrawable);

系统条配置SystemBarConfig
开发者不需要关心系统UI的大小和位置。android:fitsSystemWindows=”true”和android:clipToPadding=”false”结合使用可以实现内容全屏模式下在系统UI内有padding填充的最佳布局。然而,某些元素比如GoogleMap强制要求系统条的内部值,以提供最佳的布局效果。
使用由SystemBarTintManager提供的SystemBarConfig类对象,可以访问这些内部值。

4 部署

下载JAR
https://github.com/jgilfelt/SystemBarTint
Gradle:
compile ‘com.readystatesoftware.systembartint:systembartint:1.0.4’

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值