要配置状态栏和导航栏为透明色,然后让内容显示在状态栏之后,可以通过主题或者给 window 设置 flag 来实现,但是只有在 4.4 及其以上版本支持,4.4 和5.0还需要使用不同的配置,所以对不同的版本使用不同的style文件
在 values、values-v19、values-v21 文件夹中添加下面对应的 styles.xml代码(没有的可自行创建),在文件中自定义主题
values:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
values-v19:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
values-v21:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>