1. 需注意只有5.0以上适用,以下需要适配处理,否则程序会崩掉。
一、values-v19/styles.xml 无效果,仅防止低版本崩掉
<resources>
<!--values-v19。v19 开始有 android:windowTranslucentStatus 这个属性-->
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
二、values-v21/styles.xml
<resources>
<!--values-v21 5.0 以上提供了 setStatusBarColor() 方法设置状态栏颜色。-->
<style name="TranslucentTheme" 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>
</resources>
使用:只需给activity设置主题
android:theme="@style/TranslucentTheme"
[1]本文由张风捷特烈原创,转载