내 애플리케이션에서 각 listView 항목의 배경색을 변경하려고합니다. 그리고 그 때문에 레이어 목록에있는 모양을 사용하고 있습니다. 여기java.lang.ClassCastException : android.graphics.drawable.LayerDrawable을 android.graphics.drawable.GradientDrawable에 캐스팅 할 수 없습니다.
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"/>
나는
private void setRoundedBackground(View view,int color){
GradientDrawable gradientDrawable;
gradientDrawable = (GradientDrawable) view.getBackground().mutate();
gradientDrawable.setColor(getResources().getColor(color));
gradientDrawable.invalidateSelf();
}
가 어떻게 ClassCastException이 얻을 수있다 LayerDrawable의 GradientDrawable ?
그것은 당신이 원하는에 따라 달라집니다 – fish40
최고의 솔루션으로 여기 변경해야합니까 GradientDrawable 함께 할 – pshegger
단색을 프로그래밍 방식으로 변경하고 싶습니다 (이 예제에서는 color11) – fish40