1.添加依赖包
// 基础依赖包,必须要依赖
implementation 'com.gyf.immersionbar:immersionbar:3.0.0-beta07'
// fragment快速实现(可选)
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0-beta07'
2.配置
关于全面屏
在manifest加入如下配置,四选其一,或者都写
① 在manifest的Application节点下加入
<meta-data
android:name="android.max_aspect"
android:value="2.4" />
② 在manifest的Application节点中加入
android:resizeableActivity="true"
③ 在manifest的Application节点中加入
android:maxAspectRatio="2.4"
④ 升级targetSdkVersion为25以上版本
关于刘海屏
在manifest的Application节点下加入,vivo和oppo没有找到相关配置信息
<!--适配华为(huawei)刘海屏-->
<meta-data
android:name="android.notch_support"
android:value="true"/>
<!--适配小米(xiaomi)刘海屏-->
<meta-data
android:name="notch.config"
android:value="portrait|landscape" />
3.使用
ImmersionBar.with(this).init();
4.使用后若出现重叠解决办法
使用dimen自定义状态栏高度
在values-v19/dimens.xml文件下
<dimen name="status_bar_height">25dp</dimen>
原处:github :https://github.com/gyf-dev/ImmersionBar
博客:https://www.jianshu.com/p/2a884e211a62