Now you can Subscribe using RSS

Submit your Email


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

Vishal Shrestha
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

Vishal Shrestha / Author & Founder

A developer by profession, a born Adventurer. I mainly do Android but like to get my hands dirty with web development and a little bit of Python. I would't rather go on a Trek than a party and you can find me having a few rounds with the heavy bag to let out the steam ;)


Research and Development at : Ekghanti

Mobile Technology Lead at : Vimvox Lab

For Business info : My Portfolio Site


Post a Comment

Coprights @ 2017 | The Code City by Vishal Shrestha Vishal Shrestha