How can i create a button with no text and an image centered horizontally ? I don't want to use an ImageButton because I want to define a different backgound image
Asked
Active
Viewed 1.8e+01k times
4 Answers
206
You just use an ImageButton and make the background whatever you want and set the icon as the src.
<ImageButton
android:id="@+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/album_icon"
android:background="@drawable/round_button" />
-
3Please justify and descrive more about android:background! – E A Apr 15 '15 at 10:58
-
3@EmadAghayi src is the actual icon that will be used in the ImageButton; background is the shape of the original button, which is a rectangle by default. If you want to use only the image, you can omit it, or you can use other colors/shapes around the icon. – ocramot May 25 '17 at 15:47
22
just use a Button with android:drawableRight properties like this:
<Button android:id="@+id/btnNovaCompra" android:layout_width="wrap_content"
android:text="@string/btn_novaCompra"
android:gravity="center"
android:drawableRight="@drawable/shoppingcart"
android:layout_height="wrap_content"/>

user2347796
- 251
- 2
- 3
12
You can just set the onClick of an ImageView and also set it to be clickable, Or set the drawableBottom property of a regular button.
ImageView iv = (ImageView)findViewById(R.id.ImageView01);
iv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});

Patrick Kafka
- 9,795
- 3
- 29
- 44
1
You can use the button :
1 - make the text empty
2 - set the background for it
+3 - you can use the selector to more useful and nice button
About the imagebutton you can set the image source and the background the same picture and it must be (*.png) when you do it you can make any design for the button
and for more beauty button use the selector //just Google it ;)

Oubaida AlQuraan
- 1,706
- 1
- 18
- 19