【发布时间】:2016-12-15 14:46:59
【问题描述】:
请检查选项 1 和选项 2,在 values-v21 样式中定义平台特定样式属性(如 android:colorPrimary)有什么好处。
values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="CommonTheme">
</style>
<style name="CommonTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
选项 1:values-v21/styles.xml - 通过继承对所有版本使用 AppCompact。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="CommonTheme">
<!-- All customization of the theme for this version -->
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
选项 2:values-v21/styles.xml - 编写特定于平台的样式属性以及继承。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="CommonTheme">
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
我在不同的地方看到这两个选项,哪个更好?我们在选项 2 中有什么优势吗?
【问题讨论】:
标签: android styles android-appcompat