使用环境:
需要对标题栏做处理的时候。
清单文件application引用theme属性
<application
android:name="LoveApplication"
android:allowBackup="true"
android:usesCleartextTraffic="true"
android:icon="@drawable/icon_app_logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:replace="android:icon,android:theme"
android:theme="@style/TranslucentTheme">
这里的TranslucentTheme:
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:statusBarColor">@android:color/white</item>
</style>
statusBarColor就可以设置为colorPromaryDark,都可以用来设置手机顶部任务栏的背景颜色。
正文:
ColorPrimaryDark 与 StatusBarColor 区别
相同点:‘
Android 5.0以上支持
不同点:
statusBarColor 更高级
如果他们同时出现,statusBarColor 会覆盖colorPrimaryDark
默认情况下,statusBarColor会集成ColorPrimaryDark
使用:
在application下使用theme属性时,
value-21下的属性声明方式:
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:statusBarColor">@android:color/white</item>
</style>