Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add image(left) and text on button

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


For illustration:

enter image description here

like image 321
Roy Lee Avatar asked Jun 23 '13 06:06

Roy Lee


People also ask

Can image button have text?

ImageButton can't have text (or, at least, android:text isn't listed in its attributes).

How will you add graphics to button?

Copy your image file within the Res/drawable/ directory of your project. While in XML simply go into the graphic representation (for simplicity) of your XML file and click on your ImageButton widget that you added, go to its properties sheet and click on the [...] in the src: field. Simply navigate to your image file.


1 Answers

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 ); 
like image 159
Michael Shrestha Avatar answered Sep 24 '22 03:09

Michael Shrestha