Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit Iv: User Interface Widgets

Download as pdf or txt
Download as pdf or txt
You are on page 1of 99

UNIT IV

User Interface Widgets


4.1 Text Control:
1. TextView

• In android, TextView is a user interface control that is used to


Set and Display the text.
• TextView control will act as like label control and it won’t allow users
to edit the text.
Attribute Description

android: id It is used to uniquely identify the control

android:width It makes the TextView be exactly this many pixels wide.

android:height It makes the TextView be exactly this many pixels tall.

android:text It is used to display the text.

android:textSize It is used to specify the size of the text

android:textStyle It is used to change the style (bold, italic, bold | italic) of text.

android:textAllCaps It is used to present the text in all CAPS

android:typeface It is used to specify the Typeface (normal, sans, serif,


monospace) for the text.
2. EditText/ PlainText
• In android, EditText is a user interface control which is used to allow
the user to enter or modify the text.
• While using EditText control in our android applications, we need to
specify the type of data the text field can accept using
the inputType attribute.
• For example, if it accept plain text, then we need to specify the
inputType as “text”. In case if EditText field is for password, then we
need to specify the inputType as “textPassword”.
• In android, EditText control is an extended version
of TextView control with additional features and it is used to allow
users to enter input values.
Attribute Description

android: id It is used to uniquely identify the control

android:width It makes the TextView be exactly this many pixels wide.

android:height It makes the TextView be exactly this many pixels tall.

android:text It is used to display the text.

android:textSize It is used to specify the size of the text

android:textStyle It is used to change the style (bold, italic, bold | italic) of text.

Android:hint As like placeholder

android:typeface It is used to specify the Typeface (normal, sans, serif,


monospace) for the text.

android:ems It is used to make the textview be exactly this many ems wide.
TextControl
• TextView
• PlainText
• Password
• Password(Number)
• E-Mail
• Phone
• Postal Address
• Multiline Text
• Time
• Date
• Number
• Number (Signed)
• Number (Decimal)
4.2 Button Control
• In android, Button is a user interface control that is used to perform an
action whenever the user clicks or tap on it.

• Generally, Buttons in android will contain a text or an icon or both and


perform an action when the user touches it.
• In android, we have a different type of buttons available to use based
on our requirements, those
are ImageButton, ToggleButton, RadioButton.
4.3 Toggle Button
• In android, Toggle Button is a user interface control that is used to
display ON (Checked) or OFF (Unchecked) states as a button with a
light indicator.
• The ToggleButton is useful for the users to change the settings
between two states either ON or OFF. We can add a ToggleButton to
our application layout by using the ToggleButton object.
• By default, the android ToggleButton will be in OFF (Unchecked)
state. We can change the default state of ToggleButton by using
android:checked attribute.

• In case, if we want to change the state of ToggleButton


to ON (Checked), then we need to set android:checked = “true” in
our XML layout file.
4.4. Image Button
• In android, Image Button is a user interface control that is used to
display a button with an image and to perform an action when a user
clicks or taps on it.

• By default, the ImageButton looks same as normal button and it


performs an action when a user clicks or touches it, but the only
difference is we will add a custom image to the button instead of text.
• In android, we have different types of buttons available to use based
on our requirements, those are Button, ImageButton, ToggleButton,
and RadioButton.

• In android, we can add an image to the button by


using <ImageButton> attribute android:src in XML layout file or by
using the setImageResource() method.
2. CheckBox
• In android, CheckBox is a two-states button that can be either checked
(ON) or unchecked (OFF) and it will allow users to toggle between the
two states (ON / OFF) based on the requirements.
• Generally, we can use multiple CheckBox controls in android
application to allow users to select one or more options from the set of
values.
• By default, the android CheckBox will be in the OFF (Unchecked)
state. We can change the default state of CheckBox by
using android:checked attribute.
• In case, if we want to change the state of CheckBox to ON (Checked),
then we need to set android:checked = “true” in our XML layout file.
3. Radio Button
• In android, Radio Button is a two-states button that can be either
checked or unchecked and it’s the same as CheckBox control, except
that it will allow only one option to select from the group of options.
• The user can press or click on the radio button to make it select. In
android, CheckBox control allow users to change the state of control
either Checked or Unchecked but the radio button cannot be
unchecked once it is checked.
• Generally, we can use RadioButton controls in an android application
to allow users to select only one option from the set of values.
m

• In android, we use radio buttons with in a RadioGroup to combine


multiple radio buttons into one group and it will make sure that users
can select only one option from the group of multiple options.
• By default, the android RadioButton will be in OFF (Unchecked)
state. We can change the default state of RadioButton by
using android:checked attribute.
• In case, if we want to change the state
of RadioButton to ON (Checked), then we need to
set android:checked = “true” in our XML layout file.
Switch
• In android, Switch is a two-state user interface element that is used
to display ON (Checked) or OFF (Unchecked) states as a button with
thumb slider. By using thumb, the user may drag back and forth to
choose an option either ON or OFF.
• The Switch element is useful for the users to change the settings
between two states either ON or OFF. We can add a Switch to our
application layout by using Switch object.
AutoCompleteTextView View
• Android AutoCompleteTextView completes the word based on the
reserved words, so no need to write all the characters of the word.
• Android AutoCompleteTextView is a editable text field, it displays a
list of suggestions in a drop down menu from which user can select
only one suggestion or value.
• Android AutoCompleteTextView is the subclass of EditText class. The
MultiAutoCompleteTextView is the subclass of
AutoCompleteTextView class.
• Using Array Adapter To Display Text Values In AutoCompleteTextView:
• To display the Array content in an autocompletetextview we need to
implement Adapter. In AutoCompleteTextView we mainly display text values so
we use Array Adapter for that.
• ArrayAdapter In Android:
• ArrayAdapter is used when we need list of single type of items which is backed by
an Array. For example, list of phone contacts, countries or names.
• ArrayAdapter code:
4.7 WebView
• Android WebView is used to display web page in android. The web
page can be loaded from same application or URL. It is used to display
online content in android activity.
• Android WebView uses webkit engine to display web page.
• The android.webkit.WebView is the subclass of AbsoluteLayout class.
• The loadUrl() and loadData() methods of Android WebView class are
used to load and display web page.
package example.javatpoint.com.webview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mywebview = (WebView) findViewById(R.id.webView);
mywebview.loadUrl("https://www.google.com/");

}
}
4.6 AnalogClock and DigitalClock Views
• Analog and digital clocks are used for display the time in android
application.
1.Analog clock: Analog clock is a subclass of View class. It represents
a circular clock. Around the circle, numbers 1 to 12 appear to represent
the hour and two hands are used to show instant of the time- shorter
one for the hour and longer is for minutes.
2.Digital clock: Digital clock is subclass of TextView Class and uses
numbers to display the time in “HH:MM” format.
4.5 TimePicker View, DatePicker View
• Date Picker and Timer Picker Dialog in our android application. These
components are used to select date and time in a customized user
interface. We will use DatePickerDialog and TimePickerDialog classes
with Calendar class in our android application code to achieve this.
https://www.journaldev.com/9976/android-date-time-picker-dialog
4.8 Toast Notification
• In android, Toast is a small popup notification that is used to display an
information about the operation which we performed in our app. The Toast
will show the message for a small period of time and it will disappear
automatically after a timeout.
• Generally, the size of Toast will be adjusted based on the space required for
the message and it will be displayed on the top of the main content
of activity for a short period of time.

• For example, some of the apps will show a message like “Press again to
exit” in toast, when we pressed a back button on the home page or showing
a message like “saved successfully” toast when we click on the button to
save the details.
Text controls (For more study-Refer )
4.3 Toggle buttons (For More Study-Refer)
Take a Look
4.8 Toast Notification
• In android, Toast is a small popup notification that is used to display
an information about the operation which we performed in our app.
The Toast will show the message for a small period of time and it will
disappear automatically after a timeout.
• For example, some of the apps will show a message like “Press again
to exit” in toast, when we pressed a back button on the home page or
showing a message like “saved successfully” toast when we click on
the button to save the details.

You might also like