Ktl-icon-tai-lieu

Android

Được đăng lên bởi Lê Công Tuấn
Số trang: 27 trang   |   Lượt xem: 429 lần   |   Lượt tải: 0 lần
Trường ðại học Bách Khoa Hà Nội
Hanoi University of Science and Technology

Chapter 4. Graphical User
Interfaces
Hanoi University of Science and
Technology
Nguyen Hong Quang
19/8/2012

© HUST 2012

Content
4.4a. Menu
Option Menus
Context Menus

4.4b. Showing Pop-Up Messages

Ví dụ - XML Layout
<LinearLayout
android:orientation="vertical“ >
<TextView
android:id="@+id/selection“
/>
<ListView
android:id="@+id/list“
/>
</LinearLayout>

Adding “options menu”

Adding “options menu”

Adding “context menu”

Option menu
The options menu is triggered by pressing the
hardware "Menu button” on the device
In addition, the options menu operates in one of
two modes: icon and expanded.
When the user first presses the "Menu button,
the icon mode will appear, showing up to the
first six menu choices as large, finger-friendly
buttons in a grid at the bottom of the screen.

Option menu
If the menu has more than six choices, the sixth
button will become "More" – clicking that option
will bring up the expanded mode, showing the
remaining choices not visible in the regular
menu.
The menu is scrollable, so the user can get to
any of the menu choices.

Context menu
On a traditional GUI, this might be triggered by
the right-mouse button. On mobile devices,
context menus typically appear when the user
"taps-and-holds” over a particular widget.
For example, if a TextView had a context menu,
and the device was designed for finger-based
touch input, you could push the TextView with
your finger, hold it for a second or two, and a
popup menu will appear for the user to choose
from.

Option menu
Display Option menu:

public boolean onCreateOptionsMenu(Menu
menu);
Process item menu selected events:

public boolean
onOptionsItemSelected(MenuItem item);
item.getItemId()

Context menu
Display context menu:

public void
onCreateContextMenu(ContextMenu menu,
View v, ContextMenuInfo menuInfo);
Process item menu selected events:

public boolean
onContextItemSelected(MenuItem item);

Example: ListView with Menus

XML Layout: main.xml
<LinearLayout>
<TextView
android:id="@+id/text"
/>
<ListView
android:id="@+id/list"
/>
</LinearLayout>

Option menu : Layout
option.xml
<menu xmlns:android="" >
<item android:id="@+id/add"
android:title="Add"
android:icon="@drawable/ic_menu_add"
/>
<item
android:id="@+id/reset"
android:title="Reset"
android:icon="@drawable/ic_menu_refresh“
/>
</menu>

Context menu : Layout
context.xml
<menu xmlns:android="http://...
Chapter 4. Graphical User
Interfaces
Hanoi University of Science and
Technology
Nguyen Hong Quang
19/8/2012
Trường ðại học Bách Khoa Hà Nội
Hanoi University of Science and Technology
© HUST 2012
Android - Trang 2
Để xem tài liệu đầy đủ. Xin vui lòng
Android - Người đăng: Lê Công Tuấn
5 Tài liệu rất hay! Được đăng lên bởi - 1 giờ trước Đúng là cái mình đang tìm. Rất hay và bổ ích. Cảm ơn bạn!
27 Vietnamese
Android 9 10 451