0

Hallo ich habe Knopf mit zwei Bildern, die nach links und rechts zeichnbar sind, ich möchte nur linkes Seitenbild entfernen, und will das rechte Seitenbild behalten, mein Knopf xml Code ist unten.Programmatisch entfernen Sie das Bild auf der linken Seite der Schaltfläche, aber nicht auf der rechten Seite?

<Button 
    android:id="@+id/fragment_add_to_cart_btn_proceed_to_checkout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorRed" 
    android:drawableEnd="@drawable/ic_action_next" 
    android:drawablePadding="5dp" 
    android:drawableStart="@drawable/ic_rounded_cart" 
    android:gravity="left|center_vertical" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:text="@string/proceed_to_checkout" 
    android:textColor="@color/colorWhite" /> 

Ich habe einige Code wie unten angewendet, aber es ist nicht

button.setCompoundDrawables(null, null, null, null);

arbeiten, wenn Sie eine Lösung haben, antworten Sie bitte? danke.

+1

Entfernen Sie einfach die folgende Zeile: 'android: drawableStart = "@ ziehbar/ic_rounded_cart"' –

+0

Ich möchte dies programmatisch tun. –

+1

Verwenden Sie dann 'button.setCompoundDrawablesWithIntrinsicBounds (null, null, Ihr_rechts_Zeichensatz, null); 'Referenz: https://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int,%20int,%20int, % 20int) –

Antwort

1

tun, wie diese innerhalb onCreate. Geben Sie image Ressource für die Sie sonst zeigen müssen, wird 0 gegeben.

int imgResource = R.drawable.common_google_signin_btn_icon_dark; 
fragment_add_to_cart_btn_proceed_to_checkout = (Button) findViewById(R.id.fragment_add_to_cart_btn_proceed_to_checkout); 
fragment_add_to_cart_btn_proceed_to_checkout.setCompoundDrawablesWithIntrinsicBounds(0, 0, imgResource, 0); 
1

versuchen

button.setCompoundDrawablesWithIntrinsicBounds(0, 0, <your_left_drawable>, 0); 

Hoffe, dass es Ihnen helfen wird.

1

sollten Sie button.setCompoundDrawables(null, null, R.drawable.ic_action_next, null);

1

try:

button.setCompoundDrawablesWithIntrinsicBounds(0, 0, <The right drawable>, 0); 

Auftrag:

setCompoundDrawablesWithIntrinsicBounds (int left, int top, int right, int bottom) 
1
button.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_rounded_cart, 0); // if you want to remove the left drawable 
Verwandte Themen