在Android

时间:2017-04-23 18:21:58

标签: android xml

我在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>

0 个答案:

没有答案