安卓开发

安卓实现沉浸式状态栏

2020-11-25  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读