Search code examples
androidkotlinmaterial-design

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>

Solution

  • 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.