Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "Failed to inflate ColorStateList, leaving it to the framework" when using ShapeableImageView

I'm able to use the ShapeableImageView to show cornered image but when I check the log, there are error but no idea what is it about and how to fix it. When I change the view into ImageView, this error no longer showing but I can't make use of the cornered image feature(shapeAppearanceOverlay)

This is the error log:

W/ResourcesCompat: Failed to inflate ColorStateList, leaving it to the framework
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f0300fc a=-1}
    at android.content.res.TypedArray.getColor(TypedArray.java:556)
    at androidx.core.content.res.ColorStateListInflaterCompat.inflate(ColorStateListInflaterCompat.java:160)
    at androidx.core.content.res.ColorStateListInflaterCompat.createFromXmlInner(ColorStateListInflaterCompat.java:125)
    at androidx.core.content.res.ColorStateListInflaterCompat.createFromXml(ColorStateListInflaterCompat.java:104)
    at androidx.core.content.res.ResourcesCompat.inflateColorStateList(ResourcesCompat.java:229)
    at androidx.core.content.res.ResourcesCompat.getColorStateList(ResourcesCompat.java:203)
    at androidx.core.content.ContextCompat.getColorStateList(ContextCompat.java:519)
    at androidx.appcompat.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:48)
    at d.b.a.e.v.c.a(MaterialResources.java:60)
    at com.google.android.material.imageview.ShapeableImageView.<init>(ShapeableImageView.java:112)
    at com.google.android.material.imageview.ShapeableImageView.<init>(ShapeableImageView.java:92)
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at android.view.LayoutInflater.createView(LayoutInflater.java:852)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
    at f.a.a.b.d.b.d(ActivityInstallerTrackerBinding.java:164)
    at f.a.a.b.d.b.c(ActivityInstallerTrackerBinding.java:158)
    at mypackage.MyActivity.onCreate(MyActivity.kt:64)
    at android.app.Activity.performCreate(Activity.java:8006)
    at android.app.Activity.performCreate(Activity.java:7990)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3584)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2246)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:233)
    at android.app.ActivityThread.main(ActivityThread.java:8010)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

This is my code at line 64

private lateinit var binding: MyActivityBinding
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = MyActivityBinding.inflate(layoutInflater) << Line 64
    setContentView(binding.root)

    initView()
}

I tried to add app:errorTextAppearance to the ShapeableImageView as I saw that solution for this exact error but for TextInputLayout, but still having that error.

Edit: Including the ShapeableImageView xml & the style

<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin8"
            android:background="@drawable/corner_bg"
            android:gravity="center"
            android:orientation="horizontal"
            android:visibility="gone"
            app:layout_constraintEnd_toStartOf="@+id/glRight"
            app:layout_constraintStart_toEndOf="@+id/glLeft"
            app:layout_constraintTop_toBottomOf="@+id/tvUpload"
            tools:visibility="visible">
            <com.google.android.material.imageview.ShapeableImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:shapeAppearanceOverlay="@style/roundedImageView"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:padding="1dp"
                android:alpha="0.5"
                android:maxHeight="100dp"
                android:minHeight="100dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/margin16"
                android:layout_weight="1"
                android:drawablePadding="@dimen/margin8"
                android:fontFamily="@font/din_condensed_bold"
                android:gravity="center"
                android:text="@string/select_successful"
                android:textSize="20sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@+id/ivRemove"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <ImageView
                android:id="@+id/ivRemove"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/margin16"
                android:src="@drawable/ic_close2"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>

And this is the style

<style name="roundedImageView" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">10dp</item>
</style>
like image 513
Mike Avatar asked Dec 10 '25 11:12

Mike


2 Answers

Add the following to the ShapeableImageView:

app:strokeColor="@null"

This stopped the logcat output for me. There appears to be an issue in the library.

like image 119
Tom Gilbert Avatar answered Dec 12 '25 03:12

Tom Gilbert


General method for debugging errors of the following form:

Failed to inflate ColorStateList, leaving it to the framework java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0xNNNNNNNN a=-1}

Your app is probably making use of a custom sub-theme somewhere and the parent theme is expecting the sub-theme to provide attributes that the sub-theme is not providing.

Begin by looking at the hexadecimal value found after the TypedValue token in the logcat. In the example in the original post, the value is 0x7f0300fc. Look for this value in the R.java files generated by your Android application's build procedure (or run aapt2 dump resources path/to/app.apk). Hopefully you'll see something like the following:

public static final int styleAttributeXxx=0x7f04015a;

where styleAttributeXxx is something like colorOnSecondaryContainer or shapeAppearanceSmallComponent. What you need to do now is figure out which attribute is associated with this styleAttributeXxx. For example, in the case of colorOnSecondaryContainer the attribute could be rippleColor; in the case of shapeAppearanceSmallComponent, the attribute could be shapeAppearance. It can be tricky to get the proper associations, so try browsing the Material md files.

The attribute needs to be present and correct in your developer-provided styles xml in order to avoid the error messages.

So to solve this, for each problematic attribute,

  • Ensure that the attribute is present and assigned to something (such as transparent or null) in your styles xml. For example, using the attributes from my examples, you might add the following:
<item name="rippleColor">@android:color/transparent</item>

OR

<item name="strokeColor">@null</item>
  • Ensure that the android: prefix is appropriately absent or present in your styles xml. For example, you might need to change android:backgroundTint to backgroundTint.
like image 24
Jo Jo Avatar answered Dec 12 '25 02:12

Jo Jo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!