Frage

Ist es möglich, eine ziehbar auf einer Schaltfläche über Java zu ändern?

Beispiel; Ich habe eine Schaltfläche wie folgt aus.

<Button 
style="@style/Buttons" 
android:id="@+id/butFavTeam"
android:drawableBottom="@drawable/venue"/>

Ich mag mit einem anderen aus meinem ziehbar Verzeichnis das aktuelle drawableBottom Bild ändern.

War es hilfreich?

Lösung

Haben Sie bei dieser Methode angesehen:

/*
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.
*/
public void  setCompoundDrawablesWithIntrinsicBounds  (Drawable left, Drawable top, Drawable right, Drawable bottom)

Versuchen Sie diese:

/*remember to first clear the callback of the drawable you are replacing to prevent memory leaks...
* Get the Drawables for the button by calling: myButton.getCompoundDrawables(), then loop through that calling myOldDrawable.setCallback(null);
* e.g:*/

for(Drawable myOldDrawable : myButton.getCompoundDrawables())
{
   myOldDrawable.setCallback(null);
}

//use null where you don't want a drawable
myButton.setCompoundDrawablesWithIntrinsicBounds(null,null,null, myNewDrawable);

Ich hoffe, das hilft.

Andere Tipps

fand es einfach.

Drawable myIcon = this.getResources().getDrawable(R.drawable.myVenue);
butFavTeam.setCompoundDrawablesWithIntrinsicBounds(null, null, null, myIcon);

Übrigens ... stellen Sie sicher, verwenden Sie nicht versehentlich die Methode setCompoundDrawables (). Es nimmt die gleichen Parameter wie setCompoundDrawablesWithIntrinsicBounds (), aber es ist offensichtlich einige Grenzen Details erwartet zu.

Ich fiel Beute für das, weil ich faul das erste Type-Ahead-Verfahren akzeptiert. Ich bin dies bei Buchung können auch Sie nicht herausfinden, warum die Bilder nicht angezeigt werden.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top