Android Tutorial

(avery) #1
Android Tutorial 181

A ToggleButton is similar to a CheckBox, but you use it to visually
show the state. The default behavior of a toggle is like that of a
power on/off button.

A RadioButton provides selection of an item. Grouping RadioButton
controls together in a container called a RadioGroup enables the
developer to enforce that only one RadioButton is selected at a
time.

Using Basic Buttons

The android.widget.Button class provides a basic button
implementation in the Android SDK. Within the XML layout
resources, buttons are specified using the Button element. The
primary attribute for a basic button is the text field. This is the label
that appears on the middle of the
button’s face. You often use basic Button
controls for buttons with text such as
“Ok,”“Cancel,” or “Submit.”

Various types of button controls.

The following XML layout resource file
shows a typical Button control definition:

<Button
android:id=”@+id/basic_button”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Basic Button” />


A button won’t do anything, other than
animate, without some code to handle
Free download pdf