Adding a Background Image and text to a Button in Android example

I played around with the properties of buttons in XML and figured a way to write over the background image of a button properly. This is pretty simple, but you will have to adjust the padding to place the text in desired position over the image. The ideal way to customize you button are using selectors, but i had different images for different buttons. You can learn to customize buttons using selectors here.
The background image must be placed inside the resources/drawable folder.
Here’s the XML code-


       android:id="@+id/bangry"                     //Button id
       android:text="Angry"                            //text we want 
                                                                      //over the image
       android:textSize="15sp"                       //Text size
                                            //Link to the BG image

Here’s what the button looks like-

Learn customizing android buttons using- Selectors in Android

Don’t miss these tips!

We don’t spam! Read our privacy policy for more info.

Sharing is caring!

Leave a Comment

Your email address will not be published.