Exploring User Interface Screen Elements: By: Mitul Patel
Exploring User Interface Screen Elements: By: Mitul Patel
activity_main.xml
Checking User Inputs with Input Filters
• Sometimes requirement comes in a way when one needs to
restrict characters to be entered in Edit Text. Scenario can be
“username should be greater than 6 characters”, “accepts
only decimal number with 2 digits after fraction”, etc.
Helping the User with Autocompletion
AutoCompletionTextView
Adapter in Android
• In Android, Adapter is a bridge
between UI component and
data source that helps us to fill
data in UI component. It holds
the data and send the data to
an Adapter view then view can
takes the data from
the adapter view and shows the
data on different views like
as ListView, GridView, Spinner e
tc
ArrayAdapter In Android
• Whenever we have a list of single items which is backed by an
Array, we can use ArrayAdapter. For instance, list of phone
contacts, countries or names.
“MainActivity.java” for
AutoCompletionTextView
MultiAutoCompleteTextView
• One most important difference
between MultiAutoCompleteTextView and AutoCompleteTextView
is that AutoCompleteTextView can hold or select only single value
at single time but MultiAutoCompleteTextView can hold multiple
string words value at single time. These all values are separated by
comma(,).
MultiAutoCompleteTextView Example
Giving Users Choices Using Spinner Controls
• It can be used to display the multiple options to the user in which
only one item can be selected by the user.
• Android spinner is like the drop down menu with multiple values
from which the end user can select only one value.
• Android spinner is associated with AdapterView. So you need to
use one of the adapter classes with spinner..
Giving Users Choices Using Spinner Controls
File: MainActivity.java
The code to display item on the spinner
and perform event handling
User Selections with Buttons and Switches
• Using Basic Buttons
• Using Checkbox and ToggleButton Controls
• Using RadioGroup and RadioButton
Using Basic Buttons
• A basic Button is often used to perform some sort of action,
such as submitting a form or confirming a selection.
• A basic Button control can contain a text or image label.
• The android.widget.Button class provides a basic Button
implementation in the Android SDK.
• Common Button Text such as “Yes”,”No”,”OK”,”Cancel” or
“Submit”.
A Button Listener
• A button won’t do anything, other than animate, without
some code to handle the click event.
ImageButton
• A button with its primary label as an image is an ImageButton.
• An ImageButton is, for most purposes, almost exactly like a basic
button.
• Click actions are handled in the same way. The primary difference
is that you can set its src attribute to be an image
Checkbox Control
• The check box button is often
used in lists of items where the
user can select multiple items.
• The Android check box contains a
text attribute that appears to the
side of the check box.
• This is used in a similar way to
the label of a basic button. In
fact, it’s basically a TextView next
to the button.
Checkbox Control
• In Android, CheckBox is a type of two state button either unchecked or
checked in Android. Or you can say it is a type of on/off switch that can
be toggled by the users.
• You should use checkbox when presenting a group of selectable options
to users that are not mutually exclusive. CompoundButton is the parent
class of CheckBox class.
• In android there is a lot of usage of check box. For example, to take
survey in Android app we can list few options and allow user to choose
using CheckBox.
• The user will simply checked these checkboxes rather than type their
own option in EditText. Another very common use of CheckBox is as
remember me option in Login form.
Listener on Checkbox
Example
ToggleButton
• A Toggle Button is similar to a check box in behavior but is usually used to show or
alter the on or off state of something. Like the CheckBox, it has a state (checked or
not).
• Also like the check box, the act of changing what displays on the button is handled
for us.
• Unlike the CheckBox, it does not show text next to it.
• Instead, 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.
• The most simple example of ToggleButton is doing on/off in sound, Bluetooth,
wifi, hotspot etc
ToggleButton (On/Off)
Switch (On/Off)
Second, let's disable the theme-provided ActionBar. The easiest way is to have your theme
extend from Theme.AppCompat.NoActionBar (or the light variant) within the res/values/styles.xml file:
Using Toolbar as ActionBar
Now you need to add a Toolbar to your Activity layout file
MyActivity.java for Toolbar
res/menu/menu_main.xml which is inflated above in onCreateOptionsMenu
Reusing the Toolbar
In many apps, the same toolbar can be used across multiple activities or in
alternative layout resources for the same activity. In order to easily reuse
the toolbar, we can leverage the layout include tag as follows. First, define
your toolbar in a layout file in res/layout/toolbar_main.xml:
<include /> tag to load the toolbar into our activity layout XML:
RingProgress
ProgressDialog
Styles and Themes
• Styles and themes on Android allow you to separate the details of your app design from
the UI structure and behavior, similar to stylesheets in web design.
• A style is a collection of attributes that specify the appearance for a single View. A style
can specify attributes such as font color, font size, background color, and much more.
• Styles and themes are declared in a style resource file in res/values/, usually named
styles.xml.
Styles and Themes
Create and apply a style
• You can create a theme the same way you create styles. The
difference is how you apply it: instead of applying a style with the
style attribute on a view, you apply a theme with the
android:theme attribute on either the <application> tag or an
<activity> tag in the AndroidManifest.xml file.
Dark theme