How to work with button in android?

♠ Posted by ANDROID THIRST in at 03:14
Buttons are the type of view that is created to be pressed . When the user clicks on the button in an android application the application is respond something. In this tutorial, we are going to create a different type of button .


There are three types of button in android
1.Button with Text
2. Button with Image
3.Button with Text and Image

1. Button with Text:-

Step 1. Create a project buttonWidget.

Step 2. Add following code in activity_main.xml


     
<
     Button 
 android:id="@+id/button1"
 android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:text="ClickMe" 
android:textsize="30dp"
android: background="#0000aa" />
2. Button with Image: -

 Just under the Text button use ImageButton view to create an ImageButton . Put the following code just under the Text button.
<
ImageButton
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/imageButton"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true"
      android:src="@mipmap/ic_launcher"/>
3.Button with Text and Image:- We can also create a button with Text and Image both . We can put text Left, Right, Above, 
Bellow of the Image .
'
<Button android:id="@+id/button" 
style="?android:attr/buttonStyleSmall" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="android" 
android:drawableLeft="@minmap/ic_launcher"
android:drawablePadding="10dp"/>
<HAPPY CODING>

0 comments:

Post a Comment