官方描述:
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留出空间....
举例:项目上有一个全屏的界面,界面布局文件如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/bottomSheetDialog_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BottomSheetDialog_test"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="20dp"
android:inputType="number"/>
</RelativeLayout>
</ScrollView>
布局最外层是ScrollView,为了让布局可以上下伸缩滚动,添加fillViewport属性使得布局垂直填充。为了使得界面达到全屏效果,在java文件中添加如下:
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
setContentView(R.layout.activity_main);
添加完后运行结果
发现顶部按钮和底部编辑框被系统UI(状态栏和输入法)给覆盖了。添加fitSystemWindows属性就可以解决这个问题:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:fitsSystemWindows="true">