需要满足的条件
(未验证是否为必要条件) layout最外层用
背景图用图片控件(如ImageView)而不能直接对其他ViewGroup设置background(如LinearLayout)
CoordinatorLayout和ImageView需要包含android:fitsSystemWindows="true"
需要用android:background设置资源(曾经被坑过)
该activity的style(v21)中需要添加
@android:color/transparent
true
如parent是"ActionBar"结尾的还需要添加
false
实现的效果
简易的实现
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="top.wuhaojie.week.views.TestActivity">
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@mipmap/ic_test"
android:fitsSystemWindows="true" />
另一种实现
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="top.wuhaojie.week.views.TestActivity">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:background="@mipmap/ic_test"
android:fitsSystemWindows="true" />