满足普通开发者对于沉浸式界面的开发
ImmerserLinearLayout → LinearLayout
ImmerserFrameLayout → FrameLayout
ImmerseRelativeLayout → RelativeLayout
ImmerseTableLayout → TableLayout
在需要沉浸的页面合理使用ImmerseLayout替换原本布局。
- Android Studio
在build.gradle引入 implementation 'io.github.zhangqinhao:ImmerseLayout:3.0.3'
- eclipse
建议使用As,方便版本更新。实在不行,只有复制粘贴源码了。
- 在从2.0.0版本开始,
setImmersePadding(int left, int top, int right, int bottom);
方法改为setPadding(int left, int top, int right, int bottom)
- 新增刘海屏等异型屏兼容,
app:need_immerse_notchscreen="false"
表明如果是异型屏,则不沉浸
<com.monke.immerselayout.ImmerseFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="@drawable/bg">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="背景沉浸"
android:textSize="24sp"
android:textColor="#000000"
android:background="#90ffffff"/
</com.monke.immerselayout.ImmerseFrameLayout>
<com.monke.immerselayout.ImmerseFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
app:need_immerse="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ivbg"
android:scaleType="centerCrop"/>
<com.monke.immerselayout.ImmerseLinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="布局底层ImageView沉浸,同时再次使用了一次沉浸式布局,避免内部内容也沉浸在状态栏"
android:textSize="24sp"
android:textColor="#000000"
android:background="#90ffffff"/>
</com.monke.immerselayout.ImmerseLinearLayout>
</com.monke.immerselayout.ImmerseFrameLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.monke.immerselayout.ImmerseLinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/tabcolor">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_gravity="center_horizontal"/>
</com.monke.immerselayout.ImmerseLinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.monke.immerselayout.ImmerseFrameLayout
android:id="@+id/abc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:need_immerse_notchscreen="true"
android:background="@drawable/tabcolor">
<!--android:background="#ff00ff"-->
</com.monke.immerselayout.ImmerseFrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自定义颜色"/>
</LinearLayout>
具体用法参照Sample代码