I ziehbar xml up.xml wie im folgenden Code habenWie Drawable Farbe ändern dynamisch für Schaltflächen
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<solid
android:color="@color/green" />
</shape>
</rotate>
</item>
</layer-list>
und ich habe diese ziehbar auf eine Taste angebracht, wie
folgt<Button android:id="@+id/bill_amount_up"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/up"
/>
I‘ m versuche, die Farbe des soliden Android: color = "@ color/green" in der Datei up.xml dynamisch in meinem Code zu ändern. Ich habe folgendes versucht, aber es hat nicht funktioniert.
((GradientDrawable)billAmountUp.getBackground()).setColor(color);
bekomme ich folgende Fehler java.lang.ClassCastException: android.graphics.drawable.LayerDrawable kann nicht auf android.graphics.drawable.GradientDrawable gegossen werden
Kann jemand helfen? Vielen Dank.
https://stackoverflow.com/questions/22001541/android-shape-xml-rotated-drawable-change-color-programmatically – codingnow