Now you can Subscribe using RSS

Submit your Email

Tuesday

Adding background image and text to a button

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 place inside the resources/drawable folder.
Here's the XML code-

 <Button

       android:id="@+id/bangry"                     //Button id
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"
       android:text="Angry"                            //text we want 
                                                                      //over the image
       android:paddingTop="100dp"
       android:paddingRight="75dp"
       android:textSize="15sp"                       //Text size
       android:textColor="#ffffff"
       android:background="@drawable/customangry" 
                                            //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 ;)

For Business info : My Portfolio Site.

0 comments:

Post a Comment

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