12 Star 158 Fork 28

Zackratos / UltimateBarX

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
INSTRUCTION.old.md 3.70 KB
一键复制 编辑 原始数据 按行查看 历史
Zackratos 提交于 2021-08-24 16:34 . update readme

0.7.0 以下版本使用方法

在根目录的 build.gradle 里面添加

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

在子目录的 build.gradle 中添加

dependencies {
    implementation 'com.gitee.zackratos:UltimateBarX:0.6.1'
}

ActivityFragment

val background = BarBackground.newInstance()    // 创建 background 对象
    .color(Color.TRANSPARENT)                   // 状态栏/导航栏背景颜色(色值)
    .colorRes(R.color.deepSkyBlue)              // 状态栏/导航栏背景颜色(资源id)
    .drawableRes(R.drawable.bg_common)          // 状态栏/导航栏背景 drawable
                                                // 设置背景的方法三选一即可

val config = BarConfig.newInstance()            // 创建配置对象
    .fitWindow(true)                            // 布局是否侵入状态栏(true 不侵入,false 侵入)
    .background(background)                     // 设置 background 对象
    .light(false)                               // light模式
                                                // 状态栏字体 true: 灰色,false: 白色 Android 6.0+
                                                // 导航栏按钮 true: 灰色,false: 白色 Android 8.0+

UltimateBarX.with(this)                         // 对当前 Activity 或 Fragment 生效
    .config(config)                             // 使用配置
    .applyStatusBar()                           // 应用到状态栏
    
UltimateBarX.with(this)                         // 对当前 Activity 或 Fragment 生效
    .config(config)                             // 使用配置
    .applyNavigationBar()                       // 应用到导航栏

在低版本上,light 模式不生效,可以创建一个新的 background 对象来重新设置低版本的状态栏或导航栏背景

val lvLightBackground = BarBackground.newInstance()
    .color(Color.GRAY)
    .colorRes(R.color.alphaBlack)
    .drawableRes(R.drawable.bg_gradient)

val config = BarConfig.newInstance()
    .fitWindow(true)
    .background(background)
    .light(false)
    .lvLightBackground(lvLightBackground)

UltimateBarX.with(this)
    .config(config)
    .applyStatusBar()

也可以直接链式调用

UltimateBarX.with(this)
    .fitWindow(true)  
    .color(Color.TRANSPARENT)
    .colorRes(R.color.deepSkyBlue)
    .drawableRes(R.drawable.bg_gradient)
    .light(false)
    .lvLightColor(Color.GRAY)
    .lvLightColorRes(R.color.alphaBlack)
    .lvLightDrawableRes(R.drawable.bg_yellow_alpha_black)
    .applyStatusBar()

使用 transparent 方法可以快速设置透明效果

UltimateBarX.with(this)
    .transparent()
    .applyStatusBar()

跟下面的写法效果是一样的

UltimateBarX.with(this)
    .fitWindow(false)
    .color(Color.TRANSLUCENT)
    .applyStatusBar()

使用 get 方法可以在上一次的基础上修改

例如,先用下面的代码实现状态栏变红色,不侵入,非 light 模式

UltimateBarX.with(this)
    .color(Color.RED)
    .fitWindow(true)
    .light(false)
    .applyStatusBar()

然后需要设置 light 模式,其他效果保持不变,直接用下面的方法即可

UltimateBarX.get(this)
    .light(true)
    .applyStatusBar()

当布局可侵入状态栏或导航栏时,如果需要给某个 View 增加状态栏或者导航栏的高度,可以

UltimateBarX.addStatusBarTopPadding(targetView)
UltimateBarX.addNavigationBarBottomPadding(targetView)

// 如果是 kotlin,可以直接使用扩展方法
targetView.addStatusBarTopPadding()
targetView.addNavigationBarBottomPadding()
Android
1
https://gitee.com/zackratos/UltimateBarX.git
git@gitee.com:zackratos/UltimateBarX.git
zackratos
UltimateBarX
UltimateBarX
master

搜索帮助