美文网首页安卓开发
安卓实现沉浸式状态栏

安卓实现沉浸式状态栏

作者: 蓝不蓝编程 | 来源:发表于2020-11-25 20:02 被阅读0次

效果

左侧为沉浸式

集成方法

  1. 添加依赖
implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
implementation 'com.gyf.immersionbar:immersionbar-ktx:3.0.0'
  1. Manifest中application节点下增加
<!--适配华为(huawei)刘海屏-->
<meta-data
    android:name="android.notch_support"
    android:value="true" />
<!--适配小米(xiaomi)刘海屏-->
<meta-data
    android:name="notch.config"
    android:value="portrait|landscape" />
<!--适配全面屏-->
<meta-data
    android:name="android.max_aspect"
    android:value="2.4" />
  1. 代码中设置(如activity)
private fun initImmersionBar() {
    immersionBar {
        val typedValue = TypedValue()
        theme.resolveAttribute(R.attr.colorPrimary, typedValue, true)
        statusBarColor(typedValue.resourceId).autoStatusBarDarkModeEnable(true, 0.2f)
    }
}

完整源代码

https://gitee.com/cxyzy1/ImmersionBarDemo

相关文章

网友评论

    本文标题:安卓实现沉浸式状态栏

    本文链接:https://www.haomeiwen.com/subject/gjrxiktx.html