ImmersionBar README

The project's README from github.com/gyf-dev/ImmersionBar. As one markdown file: README.md.

logo

ImmersionBar -- android 4.4以上沉浸式实现

version author 简书 QQ群

直接看效果图,建议下载demo体验,最下面有各个版本的效果图

使用(gyf替换为geyifeng)

3.1.1以上版本(mavenCentral)

// 基础依赖包,必须要依赖
implementation 'com.geyifeng.immersionbar:immersionbar:3.3.3'
// kotlin扩展(可选)
implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.3.3'
// fragment快速实现(可选)已废弃
implementation 'com.geyifeng.immersionbar:immersionbar-components:3.3.3'

3.0.0版本(jcenter)

// 基础依赖包,必须要依赖
implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
// kotlin扩展(可选)
implementation 'com.gyf.immersionbar:immersionbar-ktx:3.0.0'
// fragment快速实现(可选)
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'

版本说明

点我查看版本说明

下载demo

点我下载immersionBar-3.3.3.apk

关于全面屏与刘海

关于全面屏

在manifest加入如下配置,四选其一,或者都写

① 升级targetSdkVersion为25以上版本,现在基本都是25以上了,所以以下三个没有必要配置了

② 在manifest的Application节点中加入

   android:resizeableActivity="true"

③ 在manifest的Application节点中加入

   android:maxAspectRatio="2.4"

④ 在manifest的Application节点下加入

   <meta-data 
     android:name="android.max_aspect"
     android:value="2.4" />

关于刘海屏

在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" />

Api详解

在Activity中实现沉浸式

在Fragment中实现沉浸式

在Fragment使用ImmersionBar

在Activity使用ImmersionBar

使用Fragment第三方框架Fragmentation实现沉浸式

在Dialog中实现沉浸式,具体实现参考demo

在PopupWindow中实现沉浸式,具体实现参考demo

重点是调用以下方法,但是此方法会导致有导航栏的手机底部布局会被导航栏覆盖,还有底部输入框无法根据软键盘弹出而弹出,具体适配请参考demo。

    popupWindow.setClippingEnabled(false);

状态栏与布局顶部重叠解决方案,六种方案根据不同需求任选其一

解决EditText和软键盘的问题

当白色背景状态栏遇到不能改变状态栏字体为深色的设备时,解决方案

      ImmersionBar.with(this)
                  .statusBarDarkFont(true, 0.2f) //原理:如果当前设备支持状态栏字体变色,会设置状态栏字体为黑色,如果当前设备不支持状态栏字体变色,会使当前状态栏加上透明度,否则不执行透明度
                  .init();

状态栏和导航栏其它方法

混淆规则(proguard-rules.pro)

3.1.1以上版本无需混淆

3.0.0以下版本混淆规制

 -keep class com.gyf.immersionbar.* {*;} 
 -dontwarn com.gyf.immersionbar.**

问题汇总

点我问题汇总

效果图

说明

动态图

特别鸣谢

联系我

感谢支持

Donate

ImmersionBar (gyf-dev/ImmersionBar)

Searching Database…

What is this?ImmersionBar is an Android library that manages immersive (full-bleed) status bars and navigation bars, letting you tint status bar text, change navigation bar icon color, and handle things like rotation, notches, and the soft keyboard with minimal code.
Is this a standalone app or a library I add to my project?It is a library you add as a Gradle dependency to an existing Android app; it is not a standalone application.
How do I add it to my project?Add the ImmersionBar dependency from Maven Central for versions 3.1.1 and above (or the older JCenter artifact for 3.0.0), then call its API with one line of code in your Activity, Fragment, Dialog, DialogFragment, or PopupWindow.
Do I need anything special to use it?Just a standard Android project targeting API 19 (Android 4.4) or above; no extra SDK or external service is required.
Does it work the same on every device?No — some devices can't change status bar font color to dark even over a white background, which needs a separate workaround, and one PopupWindow method can cause the navigation bar to overlap the bottom layout or block the keyboard-driven input field from rising.
What Android versions and screen types does it support?It targets Android 4.4 and newer, and explicitly adapts for landscape/portrait switching, notch screens, and gesture navigation detection.
Does it need ProGuard rules if I shrink my app?No extra ProGuard rules are needed for version 3.1.1 and above; only versions below 3.1.1 require the proguard-rules.pro entries.
Can I check navigation bar height or visibility programmatically?Yes, it exposes static helpers like getNavigationBarHeight(), hasNavigationBar(), isNavigationAtBottom(), and getBarProperties() for a full snapshot of status/navigation bar state.
How do I avoid the status bar overlapping my layout?The README lists six approaches, from setting a fixed dimen height to using fitsSystemWindows, ImmersionBar's own statusBarView()/titleBar()/titleBarMarginTop() methods.
Does it work inside Fragments used with ViewPager2?Yes, if a Fragment's visibility is controlled by ViewPager2 with BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, you call ImmersionBar directly in onResume(); other show/hide patterns are also documented in the demo.
Creator
gyf-dev
Size
326.6 MB
Stars
11.5K
Age
9y
Commits · 90 Days