0% found this document useful (0 votes)
19 views

Exploring Android Concepts

This document discusses different UI widgets in Android like TextView, Button, ImageView, EditText, CheckBox, Switch, and RadioButtons. It describes the key attributes, properties and methods of each widget and how to use them to label things, add buttons, images, text inputs and selection controls to Android apps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Exploring Android Concepts

This document discusses different UI widgets in Android like TextView, Button, ImageView, EditText, CheckBox, Switch, and RadioButtons. It describes the key attributes, properties and methods of each widget and how to use them to label things, add buttons, images, text inputs and selection controls to Android apps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Exploring Android

Concepts: Core UI
Widgets
The attributes you’ll
see include:
• findViewById()
• getParent()
Key Methods • getRootView()
Derived from • setEnabled(), isEnabled()
• isClickable():
View
• onClickListener()
Key Attributes and Properties Derived from
View
Along with core methods from the View base class, all widgets also inherit some
key properties. These properties include:
• android:contentDescription

• android:visibility

• android:padding, android:paddingLeft, android:paddingRight,


android:paddingTop, android:paddingBottom
Labeling Things with TextView
Labeling Things with TextView (cont.)
• Your revised activity_main.xml file
Labeling Things with TextView (cont.)
• Your revised activity_main.xml file
Labeling Things Let’s introduce some new attributes
that help you control TextView and
with TextView other widgets:

(cont.) • android:layout_marginStart

• android:layout_marginEnd

• android:layout_marginLeft

• android:layout_marginRight

• android:layout_marginBottom
Labeling Things .Several key attributes that it brings to
the layout of all widgets include:
with TextView • app:layout_constraintTop_toTopOf

(cont.) • app:layout_constraintBottom_toBott
omOf
• app:layout_constraintLeft_toLeftmOf

• app:layout_constraintRight_toRightO
f
Labeling Things
with TextView
(cont.)
Labeling Things with
TextView (cont.)
To complete the picture on TextView
widgets, you should know that there are
nearly 100 different attributes that can
control behavior, style, size, color, and so
forth for a TextView label. More examples
include:
• android:hint

• android:typeface

• android:textStyle

• android.textAppearance

• android:textColor
Buttoning the
Perfect UI
• First, create a new project using
the Android Studio new project
wizard, and choose the Empty
Activity template as a starting
point. Name your project
ButtonExample (or something that
you find equally descriptive). Once
your project is created, open the
activity_main.xml file and delete
the default TextView element.
Buttoning the Perfect UI
Buttoning the
Perfect UI
Buttoning the
Perfect UI
Both ImageView and ImageButton
introduce one additional attribute to their
Getting the Picture relative element XML definition, in the
android:src value. The value of this
with ImageView attribute is a reference to an image
resource you provide, whether that’s a .png
and ImageButton file, .jpg/.jpeg file, .gif file, or some other
supported
ImageButton image format.
differs from ImageView in
supporting button-like behaviors that you
have already seen earlier in this chapter for
the regular Button widget. This means
ImageButton widgets can (and should)
have onClick listeners defined and
subsequent logic built to handle whatever
actions or behaviors you want your
application to undertake when the
ImageButton is clicked, just as you did for
the Button widget.
Getting the
Picture with
ImageView and
ImageButton
Getting the
Picture with
ImageView and
ImageButton
Editing and
Inputting Text with
EditText
EditText introduces a range of new
properties and attributes as well,
giving you fine-grained control over
exactly how your text fields look and
behave. These new attributes include:
• android:singleLine
• android:autoText
• android:password
• android:digits
Editing and
Inputting Text
with EditText
Editing and
Inputting Text
with EditText
Editing and
Inputting Text with
EditText
Checking Out the
CheckBox
The CheckBox object provides you
with some Java helper methods to
do useful things with your
checkboxes:
• toggle( )

• setChecked( )

• isChecked( )
Checking Out
the CheckBox
Checking
Out the
CheckBox
Switching It Up with a Switch

As well as the inherited properties from View and so on, a Switch widget provides the
android:text property to display associated text with the Switch state. The text is
controlled with two helper methods, setTextOn() and setTextOff(). Further methods are
available for a Switch widget, including:
• setChecked()

• getTextOn()

• getTextOff()
Switching It Up
with a Switch
Switching It Up with a
Switch
Just like other widgets, you can assign an
ID to a RadioGroup via the android:id
attribute, and using that reference as a
starting point takes advantage of the
methods available on the entire group of
RadioButtons. These methods include:
• check( )
Choosing Things
• clearCheck( )
with Radio
• getCheckedRadioButtonId( )
Buttons
Choosing
Things with
Radio Buttons
Choosing Things
with Radio
Buttons

You might also like