You are on page 1of 20

Fall 2022

MOBILE COMPUTING Lecture

Engr. Aqsa Rasheed


aqsa.se@must.edu.pk

Department of Software Engineering, MUST. Mirpur AJ&K 1


OUTLINE
▪ Input Controls

Department of Software Engineering, MUST. Mirpur AJ&K 2


INPUT CONTROLS (UI ELEMENTS)
▪ Input controls are the interactive components in app’s UI.
▪ Android provides a variety of controls for UI, such as
▪ Buttons
▪ EditText
▪ ImageView
▪ Text fields
▪ Radia Button
▪ RadioGroup
▪ CheckBox
▪ Toast
▪ Seek bars
▪ Checkboxes
▪ Zoom buttons
▪ Toggle buttons
▪ and many more.
DIFFERENT VIEWS IN
ANDROID
.

4
INPUT CONTROLS COMMON CONTROLS
BUTTON
▪ A Button is a Push-button which can be pressed, or clicked, by
the user to perform an action.
▪ A button consists of text or an icon (or both) that
communicates what action occurs when the user touches it.
BUTTON
BUTTON EVENTS
▪ To define the click event handler for a button, android:onClick
attribute is set for <Button> element in XML layout.
▪ The value for this attribute must be the name of the method
to be called in response to a click event.
▪ The Activity hosting the layout must then implement the
corresponding method.
BUTTON EVENTS
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=“Button 1“
android:onClick=“goToSecondActivity“ />

void goToSecondACtivity(View v){


// your customized code for action
}
BUTTON EVENTS

Or you can add click listeners


BUTTON EVENTS
▪ Or you can add click listeners

final Button button = findViewById(R.id.button_id);


button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
}
});
BUTTON EVENTS
▪ Or there is another way
▪ instead of (adding click listeners and setting onClick attribute)

We have already used that alternative way, just recall lab activities
BUTTONS CUSTOM BACKGROUND
▪ To create a state list drawable for button background
▪ Create three bitmaps for the that represent three button states
▪ Default
▪ Pressed
▪ Focused
▪ To ensure that images fit buttons of various sizes, create the bitmaps
as Nine-patch bitmaps
BUTTONS STYLING
▪ Button appearance will vary device to device
▪ As different manufacturers often have different default styles for
input controls
▪ You can control exactly how your controls are styled using a theme
that you apply to your entire application.
▪ android:theme="@android:style/Theme.Holo“
▪ To set background on individual buttons
▪ We can specify the android:background attribute with a drawable or color
resource
BUTTONS STYLING
▪ Custom Look
▪ To create a rounded corners for a button in Android you will
need to:
1.Create a Drawable for your Button
2.Add a Rectangle Shape to your Drawable
3.Set the Background Color in your Drawable
4.Set the Radius of the Corners in your Drawable
5.Apply the Drawable to your Button
BUTTONS STYLING
We can set custom shapes on our button using the xml
tag <shape>. These xml files are created in the drawable folder
too. shape can be used inside selectors. The shape can be set
to rectangle(default), oval, ring, line. The most used tags inside the
shape tag are:
<gradient> - Setting start and end colors of the gradient along
with the type(radius, linear, sweep)
<stroke> - Setting border color and width
<solid> - Setting the solid color on the button
<corners>- Setting radius
BUTTONS STYLING
Corner: radius
BUTTONS STYLING
Corner: bottomRightRadius
BUTTONS STYLING
THANK YOU
▪ Reading and Practice

Department of Software Engineering, MUST. Mirpur AJ&K 20

You might also like