java.lang.ClassCastException: android.graphics.drawable.LayerDrawable nie można rzutować na android.graphics.drawable.GradientDrawable

W mojej aplikacji próbuję zmienić kolor tła dla każdego elementu listView. I do tego używam kształtów, które na liście warstw. Oto mój kod

drop_shadow.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">

            <gradient android:startColor="#B7B7B7"
                      android:endColor="#A1A1A1"
                      android:angle="270"/>
            <corners android:radius="10dp" />

        </shape>
    </item>

    <item android:top="1px">

        <shape android:shape="rectangle">

            <solid android:color="@color/color11"/>
            <corners android:radius="10dp" />
        </shape>

    </item>

</layer-list>

main.xml

<RelativeLayout 
                android:orientation="vertical"
                android:id="@+id/mainLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/drop_shadow"/>

Kiedy wywołuję tę metodę, mam wyjątek ClassCastException

 private void setRoundedBackground(View view,int color){
        GradientDrawable gradientDrawable;
        gradientDrawable = (GradientDrawable) view.getBackground().mutate();
        gradientDrawable.setColor(getResources().getColor(color));
        gradientDrawable.invalidateSelf();

    }

Jak mogę uzyskać GradientDrawable z LayerDrawable?

questionAnswers(3)

yourAnswerToTheQuestion