fitSystemWindows属性:
官方描述:
Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.
简单描述:
这个一个boolean值的内部属性,让view可以根据系统窗口(如status bar)来调整自己的布局,如果值为true,就会调整view的paingding属性来给system windows留出空间....
实际效果:
当status bar为透明或半透明时(4.4以上),系统会设置view的paddingTop值为一个适合的值(status bar的高度)让view的内容不被上拉到状态栏,当在不占据status bar的情况下(4.4以下)会设置paddingTop值为0(因为没有占据status bar所以不用留出空间)。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/alpha_black_50">
<TextView
android:id="@+id/tv_cancel"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:background="@drawable/bg_corner_white_alpha_90"
android:gravity="center"
android:text="取消"
android:textColor="@color/orange"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_prompt"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_above="@id/tv_cancel"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/bg_corner_white_alpha_90"
android:gravity="center"
android:text="不再提醒"
android:textColor="@color/blue_button_1"
android:textSize="16sp"/>
</RelativeLayout>
效果: