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
Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button , with the standard button background that changes color during different button states.
In Android, ImageButton is used to display a normal button with a custom image in a button. In simple words we can say, ImageButton is a button with an image that can be pressed or clicked by the users.
To avoid confusion rename your button android:onClick="onClick" , like android:onClick="imageButtonOnClick" . Thank you!
In android, we can add an image to the button by using <ImageButton> attribute android:src in XML layout file or by using the setImageResource() method. In android, we can create ImageButton control in two ways either in the XML layout file or create it in the Activity file programmatically.
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" />
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"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With