在开发过程中,希望使用沉浸式的状态栏,即 状态栏可以与界面实现融合效果。可以使用com.readystatesoftware.systembartint:systembartint提供的类库实现此种效果。如下图所示。
【添加依赖项】
1、在Android Studio中,右击项目名称-open module settings。进入app-Dependencies-点击绿色加号,导入第三方包(依赖项)
2、选择Library Dependencies,在搜索框 输入: systembartint ,点击搜索即可,添加该依赖项即可
【代码实现】
首先在xml 布局文件中,找到包裹全部View最外层的布局元素,并设置其id:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
andr