迁移到androidx后无法将RippleDrawable转换为StateListDrawable

时间:2020-03-08 11:42:58

标签: android androidx

我不断得到

android.graphics.drawable.RippleDrawable cannot be cast to android.graphics.drawable.StateListDrawable

在下一行

StateListDrawable gradientDrawable = (StateListDrawable) view.getBackground();

在尝试将视图迁移到原位置之前并没有发生

android.support.v7.widget.AppCompatImageButton

但是现在它的

androidx.appcompat.widget.AppCompatImageButton

它不起作用

这是该视图的XML

<androidx.appcompat.widget.AppCompatImageButton
            android:id="@+id/view"
            android:layout_width="@dimen/bottomSheetPeekHeight"
            android:layout_height="@dimen/bottomSheetPeekHeight"
            android:layout_alignTop="@+id/dataEditorValueLayouts"
            android:layout_alignBottom="@+id/dataEditorValueLayouts"
            android:layout_marginEnd="@dimen/small_pad"
            android:scaleType="fitCenter"
            android:padding="@dimen/small_pad"
            app:srcCompat="@drawable/download"
            android:tint="@color/white"
            android:layout_toEndOf="@+id/dataEditorValueLayouts"
            style="@style/ButtonDefaultRuntime"
            android:visibility="visible" />

这是样式中定义的背景

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="oval">
            <solid android:color="@color/faBlue" />
            <stroke android:color="@color/button_border" android:width="3px" />
        </shape>
    </item>

    <item>
        <shape android:shape="oval">
            <solid android:color="@android:color/transparent" />
            <stroke android:color="@color/button_border" android:width="3px" />
        </shape>
    </item>
</selector>

0 个答案:

没有答案
相关问题