問題:
Consider this:考慮一下:
styles.xml樣式文件
<style name="BlueTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="theme_color">@color/theme_color_blue</item>
</style>
attrs.xml屬性文件
<attr name="theme_color" format="reference" />
color.xml顏色文件
<color name="theme_color_blue">#ff0071d3</color>
So the theme color is referenced by the theme.所以主題顏色是由主題引用的。 How can I get the theme_color (reference) programmatically?如何以編程方式獲取 theme_color (參考)? Normally I would use getResources().getColor()
but not in this case because it's referenced!通常我會使用getResources().getColor()
但在這種情況下不會使用,因爲它被引用了!
解決方案:
參考一: https://en.stackoom.com/question/1AUhG參考二: https://stackoom.com/question/1AUhG