User Interaction
Android Developer Fundamentals V2
1
1
1
Lesson 4
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
4.1 Buttons and clickable images
2
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Contents
3
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
User interaction
4
Android Developer Fundamentals V2
Buttons and clickable images
This work is licensed under a Creative Commons Attribution 4.0 International License.
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Users expect to interact with apps
5
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
User interaction design
Important to be obvious, easy, and consistent:
6
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Buttons
7
Android Developer Fundamentals V2
Button
8
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Button image assets
Experiment:
9
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Responding to button taps
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
10
android:onClick
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Setting listener with onClick callback
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
}
});
11
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Clickable images
12
Android Developer Fundamentals V2
ImageView
13
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Responding to ImageView taps
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/donut_circle"
android:onClick="orderDonut"/>
14
android:onClick
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Floating action button
15
Android Developer Fundamentals V2
Floating Action Buttons (FAB)
For example:
Add Contact button in Contacts app
16
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Using FABs
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_fab_chat_button_white"
.../>
17
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
FAB size
18
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Common Gestures
19
Android Developer Fundamentals V2
Touch Gestures
Touch gestures include:
20
Don’t depend on touch gestures for app's basic behavior!
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Detect gestures
Classes and methods are available to help you handle gestures.
21
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Detecting all types of gestures
Read more about how to handle gestures in the �Android developer documentation
22
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
Learn more
23
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
What's Next?
24
Android Developer Fundamentals V2
This work is licensed under a Creative Commons Attribution 4.0 International License.
Buttons and clickable images
END
25
Android Developer Fundamentals V2