當它是參考(主題)時以編程方式獲取顏色值 - Get color value programmatically when it's a reference (theme)

問題:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章