Roy Lee
Roy Lee

Reputation: 10842

How to add image(left) and text on button

How to add image(left) and text on button?


For illustration:

enter image description here

Upvotes: 28

Views: 25522

Answers (3)

Mahesh Babariya
Mahesh Babariya

Reputation: 4570

We can also manage the size of drawable while doing programmatically

Drawable dr = getResources().getDrawable(R.drawable.mag_green);
dr.setBounds(0, 0, 43, 40); //Left,Top,Right,Bottom
search_bar.setCompoundDrawables(dr, null , null , null);

Upvotes: 8

Michael Shrestha
Michael Shrestha

Reputation: 2555

use android:drawableLeft="@drawable/image" in your layout xml

you can also do this from code

Drawable icon= getContext().getResources().getDrawable( R.drawable.image);
button.setCompoundDrawablesWithIntrinsicBounds( icon, null, null, null );

Upvotes: 56

Everson Rafael
Everson Rafael

Reputation: 2083

        android:text="Documentos"
        android:drawableLeft= "@drawable/ic_document"

Upvotes: 10

Related Questions