在res-New-Android resource file新建values-v19的styles.xml,和values-v21的styles.xml
在原本的values-styles.xml里面
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" 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>
</style>
<style name="AppTheme" parent="AppTheme.Base"></style>
</resources>
在新建的values-v19的styles.xml里面
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
在新建的values-v21的styles.xml里面
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<!--透明状态栏-->
<item name="android:windowTranslucentStatus">true</item>
<!--透明导航栏-->
<item name="android:windowTranslucentNavigation">true</item>
<!--使状态栏,导航栏可绘制-->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
</resources>
最后清单文件中application引入(一般自己生成)
android:theme="@style/AppTheme"