app:checkedIcon="@null" in MaterialCardView is crashing in Android 9 and lower

Viewed 67

I got a Material Card view in the layout like

<com.google.android.material.card.MaterialCardView
    android:id="@+id/card_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:checkedIcon="@null"
    android:checkable="true"
    android:clickable="true">

And its crashing in Android 9.0 and lower. It works fine without app:checkedIcon="@null" . checkedIconenabled=false in styles.xml also does not work. Is there any way in XML other than setting cardView.checkedIcon = null in the code?

Thanks in advance.

1 Answers

The crash is because the drawable shouldn't be null

You can solve this by setting a transparent color instead with app:checkedIcon="@android:color/transparent"

Related