沉浸式状态栏的系统实现方式
//判断版本是否支持沉浸式状态栏
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//透明状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//透明导航栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
}
调整系统窗口布局,以便适应你的自定义布局,防止占用状态栏
设置 android:fitsSystemWindows=”true”
`
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:fitsSystemWindows="true"
android:src="@mipmap/bg"/>
`