standard android control

10
Android development Standard Android Controls (ToggleButton and Switches)

Upload: cshashank1992

Post on 05-May-2017

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: standard android control

Android development

Standard Android Controls(ToggleButton and Switches)

Page 2: standard android control

Using ToggleButton• A ToggleButton is similar to a check box in behavior.• But it displays checked/unchecked states as a button

with a "light" indicator and by default accompanied with the text "ON" or "OFF".

• It has two text fields. The first attribute is textOn, which is the text that displays on the button when its checked state is on. The second attribute is textOff, which is the text that displays on the button when its checked state is off.

• The default text for these is “ON” and “OFF,” respectively.

Page 3: standard android control

Creating ToggleButton <ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginTop="16dp" android:text="ToggleButton" />

Page 4: standard android control

Changing Text On ToggleButton

• Although a ToggleButton has a text property but it’s value does not get displayed.

• Rather to change it’s text we need to set it’s textOn and textOff properties.

• textOn displays the text when ToggleButton is in checked state

• textOff displays the text when ToggleButton is in unchecked state

Page 5: standard android control

<ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ToggleButton" android:textOff="Hide Password" android:textOn="Show Password" android:layout_below="@+id/textView1" />

Page 6: standard android control

Event Handling In ToggleButton

• It can be done in 2 ways:A.1. Implement the OnCheckedChangeListener

interface2. Register the ToggleButton object as source

and Activity class as Listener by calling the setOnCheckedChangeListener( ) method.

3. Override the method onCheckedChanged( )

Page 7: standard android control

Event Handling In ToggleButton

B.1. Implement the OnClickListener interface2. Register the ToggleButton object as source

and Activity class as Listener by calling the setOnClickListener( ) method.

3. Override the method onClick( )

Page 8: standard android control

ToggleButton Methods• public boolean isChecked()

• public void setChecked(boolean)

• public EdiTable getText()

Page 9: standard android control

Using Switch Button• A Switch is a two-state toggle switch

widget that can select between two options.

• The user may drag the "thumb" back and forth to choose the selected option, or simply tap to toggle as if it were a checkbox.

Page 10: standard android control

Creating Switch<Switch android:id="@+id/switch1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginTop="42dp" android:text="Switch Button Demo" />