资源ID类型#0x2在Samsung S3 / Note3上无效

时间:2019-06-25 09:50:56

标签: android android-xml android-resources android-color

我有一个关于Samsung S3Note 3的问题的崩溃报告(崩溃报告显示注3,而用户告诉我们它是S3)。

自定义视图会放大其布局,其中包含一个ImageView和一个tint,这不是一个color而是一个selector

Caused by android.content.res.Resources$NotFoundException
Resource ID #0x7f0501ec type #0x2 is not valid
android.content.res.Resources.getColor + 1993 (Resources.java:1993)
android.content.res.ColorStateList.twInflate + 281 (ColorStateList.java:281)
android.content.res.ColorStateList.twCreateFromXmlInner + 180 (ColorStateList.java:180)
android.content.res.ColorStateList.twCreateFromXml + 147 (ColorStateList.java:147)
android.content.res.Resources.twLoadColorStateList + 3866 (Resources.java:3866)
android.content.res.TypedArray.twGetColorStateList + 440 (TypedArray.java:440)
android.content.res.TypedArray.getColorStateList + 420 (TypedArray.java:420)
android.widget.ImageView.<init> + 184 (ImageView.java:184)
android.widget.ImageView.<init> + 140 (ImageView.java:140)
androidx.appcompat.widget.AppCompatImageView.<init> + 72 (AppCompatImageView.java:72)
androidx.appcompat.widget.AppCompatImageView.<init> + 68 (AppCompatImageView.java:68)
androidx.appcompat.app.AppCompatViewInflater.createImageView + 182 (AppCompatViewInflater.java:182)
androidx.appcompat.app.AppCompatViewInflater.createView + 106 (AppCompatViewInflater.java:106)
androidx.appcompat.app.AppCompatDelegateImpl.createView + 1266 (AppCompatDelegateImpl.java:1266)
androidx.appcompat.app.AppCompatDelegateImpl.onCreateView + 1316 (AppCompatDelegateImpl.java:1316)
android.view.LayoutInflater.createViewFromTag + 732 (LayoutInflater.java:732)
android.view.LayoutInflater.rInflate + 813 (LayoutInflater.java:813)
android.view.LayoutInflater.rInflate + 821 (LayoutInflater.java:821)
android.view.LayoutInflater.inflate + 480 (LayoutInflater.java:480)
android.view.LayoutInflater.inflate + 415 (LayoutInflater.java:415)
android.view.LayoutInflater.inflate + 366 (LayoutInflater.java:366)
android.view.View.inflate + 19573 (View.java:19573)

我认为引起问题的视图

<ImageView
        android:id="@+id/image_id"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:tint="@color/colorOnSurface"
        tools:srcCompat="@drawable/png_drawable" />

颜色

<color name="colorOnSurface">@color/white_text</color>
<color name="text_white_high">#ffffff</color>
<color name="text_white_medium">#98ffffff</color>
<color name="text_white_disabled">#61ffffff</color>
<color name="text_white_checked">?colorSecondary</color>

white_text.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/text_white_disabled" android:state_enabled="false" />
<item android:color="@color/text_white_checked" android:state_checked="true" />
<item android:color="@color/text_white_high" />
</selector>

?colorSecondary引起此问题吗?为什么只使用这种模型?

其他信息:

<style name="BaseTheme" parent="Theme.MaterialComponents">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorPrimaryLight">@color/colorPrimaryLight</item>

    <item name="colorSecondary">@color/colorSecondary</item>
    <item name="colorSecondaryLight">@color/colorSecondaryLight</item>
    <item name="colorSecondaryDark">@color/colorSecondaryDark</item>

    <!-- other attributes -->
</style>

theme_attrs.xml

<resources>
<attr name="colorPrimary" format="color" />
<attr name="colorPrimaryLight" format="color" />
<attr name="colorPrimaryDark" format="color" />
<attr name="colorSecondary" format="color" />
<attr name="colorSecondaryLight" format="color" />
<attr name="colorSecondaryDark" format="color" />
<attr name="colorBackground" format="color" />
<attr name="colorSurface" format="color" />

<attr name="colorOnPrimary" format="color" />
<attr name="colorOnSecondary" format="color" />
<attr name="colorOnBackground" format="color" />
<attr name="colorOnSurface" format="color" />
<attr name="colorOnError" format="color" />

<attr name="colorOnPrimaryMedium" format="color" />
<attr name="colorOnSecondaryMedium" format="color" />
<attr name="colorOnBackgroundMedium" format="color" />
<attr name="colorOnSurfaceMedium" format="color" />
<attr name="colorOnErrorMedium" format="color" />

<attr name="colorLightOn" format="color" />

0 个答案:

没有答案