我在attrs.xml
和主题&中定义了属性styles.xml
中的颜色。但我无法通过R.context.getColor()
获得颜色。错误:
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f01009d
相关代码段:
.java
Context context = MainActivity.getAppContext();
colorOffset = R.styleable.CellColors_cellEmpty;
int colorId = R.styleable.CellColors[colorOffset];
context.getColor(colorId)
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CellColors">
<attr name="cellEmpty" format="color"/>
<-- Additional members deducted -->
</declare-styleable>
</resources>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="cellEmpty">#eee4da</item>
<-- Additional members deducted -->
</style>
</resources>