11
Android Button BHAVIN JOSHI 125010693017 1

Android Button

Embed Size (px)

DESCRIPTION

Basic About Button in Android..

Citation preview

Page 1: Android Button

Android Button

BHAVIN JOSHI

125010693017

1

Page 2: Android Button

Index About Button

XML File

Java File

Example

2

Page 3: Android Button

XML File <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content” android:text=“radiobutton" />

<ImageButton android:id="@+id/img_button1"

android:layout_width="wrap_content" android:layout_height="wrap_content” android:src=“@drawable/droid”

/>

3

Page 4: Android Button

About Button A Basic Button is often use to perform some sort of

actions, such as submitting a selection. A basic Button control can contain a text or image label. Within the xml layout resources, button are specified

using “<button>” element. The Primary attribute for basic button is the field. This is

the label that appear on middle of button’s face. Example. We often use button control with text

“ok”,”cancel” and “submit”.

4

Page 5: Android Button

JAVA File

5

1. Create a class implements the interface button.setOnClickListener

2. Implement onClickListener() method3. Perform the action on Button using the method void

onClick().

within the onClick() method, you are free to carry out whatever action you need.

Page 6: Android Button

Example

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<ImageButton

android:id="@+id/image_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content“

android:src=“@drawable/submit/” />

<Button

android:id="@+id/button1“

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/Cancel” />

</LinearLayout>

6

Page 7: Android Button

Cont….

7

Page 8: Android Button

Java Code of Examplepackage sl.mc;

import android.os.Bundle;

import android.app.Activity;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageButton;

import android.widget.Toast;

public class MainActivity extends Activity {

ImageButton button;

Button button2;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

8

Page 9: Android Button

Cont…button=(ImageButton) findViewById(R.id.imageButton1);

button2=(Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "image button is click", Toast.LENGTH_LONG).show();

}

});

9

Page 10: Android Button

Cont…button2.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "Cancel Button is click", Toast.LENGTH_LONG).show();

}

});

}

10

Page 11: Android Button

Thank You

11