在使用以下XML属性
上android:tint="?android:attr/textColorPrimary"
使用此堆栈跟踪在某些设备上崩溃:
Caused by: java.lang.NumberFormatException: Invalid int: "res/color/abc_primary_text_material_light.xml"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
at android.content.res.TypedArray.getInt(TypedArray.java:254)
at android.widget.ImageView.<init>(ImageView.java:146)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:60)
at android.support.v7.wid
为什么是这样?有解决方案/解决方案吗?
您正在尝试使用无法在某些API级别上可用的私人资源。
在以下示例中,在res/values/colors.xml
中定义您的颜色是标准的:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="textColorPrimary">#212121</color>
<!-- other colors -->
</resources>
然后,您可以如下引用该颜色:
android:tint="@color/textColorPrimary"