什么是沉浸式状态栏:
准确来说应该是“透明栏”,英文名“Translucent Bars”,是安卓 4.4 新定义的设计规范。简单来说就是在软件打开的时候通知栏和软件顶部颜色融为一体,这样可以使软件和系统本身更加融为一体,同时通知栏的颜色不再是白色、黑色简单的两种了。如果是图片可以让其顶上去,如果或者可以设置状态栏的颜色。
比如Toolbar 和 顶部状态栏一体的颜色。
效果展示
状态1:不包含任何其他主题效果---原始效果
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:background="#ff0000"
android:layout_width="match_parent"
android:layout_height="80dp">
</LinearLayout>
</LinearLayout>
状态2: 主题增加属性windowTranslucentStatus
此时的效果是:状态栏存在并且设置为了透明颜色,此时该页面可以拉伸到顶部状态栏
相当于透明的状态栏盖在了布局上面
<item name="android:windowTranslucentStatus">true</item>