Coding Villa

How to add button widget / control using xml Button tag in android

Author : Shahzad Hemani

Share with Friends
Views : 1342
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


In this article you will learn that what a button widget / control tag in xml is and how it is added and what are its properties / attributes.


Advertisements


 

Understanding xml button tag:-

 

<Button attributes> </Button>

 

This tag is known as button tag. It is used to add an instance of button on your UI in android with its attributes you can change the size, length, width and other properties of this button.

 

Attributes:-

 

Attributes are the characteristics of Button, by providing attributes you can  modify the appearance of the button and also assign ID  to your button that will be used later on to add events on your button. Few examples of attributes are

 

Code:

 

android:text="text on button"

android:layout_width="wrap_content"

android:layout_height="wrap_content

 

Explaining these attributes:-

 

Android:text=”text on button”

 

 Android:text shows that you are talking about the text property of button which means that what text would display on the button. And =”text on the button” is the text which would be displaying on the button.

 

Android:layout_widht=”wrap_content”

 

Android:layout_widht shows that you are talking about the width of the button and “wrap_content” means that you want the width to adjust according to the width of the content on the button like in our case the width of the text we wrote on button.

 

Android:layout_height=”wrap_content”

 

Android:layout_height shows that you are talking about the height of the button and “wrap_content” means that you want the height to adjust according to the height of the content on the button like in our case the height of the text we wrote on button.

 

Code:

 

<Button android:text="text on button"

android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

 

 

This is simple article that tell you that what a button widget / control tag in xml is and how it is added and what are its properties / attributes.



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook