Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically change drawableLeft of Button

I'm using a Button

<Button
        android:id="@+id/zoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/trans"
        android:drawableLeft="@drawable/left_img"
        android:fontFamily="arial"
        android:text="My Name is "
        android:textSize="50sp" />

and changing its text color with :

zoom.setTextColor(Color.parseColor("voilet"));

but not able to understand how to change its image??

like image 578
dashh Avatar asked Aug 16 '13 16:08

dashh


1 Answers

Try this:

int imgResource = R.drawable.left_img;
button.setCompoundDrawablesWithIntrinsicBounds(imgResource, 0, 0, 0);

Reference

like image 195
Tulio Avatar answered Nov 06 '22 07:11

Tulio