THIẾT KẾ GIAO DIỆN TRÊN ANDROID Bài 6: Dialog –Input KeyboardSearch

32 187 0
THIẾT KẾ GIAO DIỆN TRÊN ANDROID  Bài 6: Dialog –Input KeyboardSearch

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

THIẾT KẾ GIAO DIỆN TRÊN ANDROID Bài 6: Dialog –Input Keyboard-Search Nội dung học Toast & AlertDialog Input Keyboard Search Toast & Alert Dialog  Sử dụng Toast Alert Dialog để kiểm tra điều đó, hay đơn giản xuất thông báo  Cả Toast Alert Dialog hiển thị lên tiến trình (hay lệnh) khác tiếp tục làm việc Toast & Alert Dialog a) Toast  Có thể sử dụng trường hợp hiển thông báo mục thiết lập thơng số cấu hình, hay đơn giản hiển thị lên để xem thơng tin tạm thời (giống để kiểm tra vấn đề xảy chẳng hạn)  Toast tạo hiển thị Activity Servive  Có thể thiết lập vị trí hiển thị toast Ví dụ: Toast xuất góc bên trái, ta viết sau: toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0); Toast & Alert Dialog a) Toast (tiếp)  Không cho phép người sử dụng tương tác  Khi hiển thị sau khoảng thời gian tự đóng lại  Có giá trị mặc định (ta nên sử dụng giá trị này, không nên gõ số cụ thể vào):  Toast.LENGTH_SHORT hiển thị giây,  Toast.LENGTH_LONG hiển thị 3.5 giây  Cách định nghĩa Toast: Context context = getApplicationContext(); CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); Toast & Alert Dialog a) Toast (tiếp): Tạo Custom Toast  Tạo tệp toast_layout.xml Toast & Alert Dialog a) Toast (tiếp): Tạo Custom Toast  Sử dụng custom toast cách gọi id: toast_layout_root LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.toast_layout_root)); TextView text = (TextView) layout.findViewById(R.id.text); text.setText("This is a custom toast"); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); Toast & Alert Dialog b) Alert Dialog  Hiển thị cho phép người dùng tương tác,  Ví dụ hình bên dưới, nhấn nút “Cancel”, chương trình hiển thị Alert Dialog hỏi xem có chắn muốn xóa hay khơng? Bấm No khơng, bấm Yes tắt chương trình Toast & Alert Dialog b) Alert Dialog (tiếp)  Cách tạo Alert Dialog: AlertDialog.Builder b=new AlertDialog.Builder(YourActivity.this); b.setTitle(“Question”); b.setMessage(“Are you sure you want to exit?”); b.setPositiveButton(“Yes”, new DialogInterface OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); }}); b.setNegativeButton(“No”, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel();} }); b.create().show(); Toast & Alert Dialog b) Alert Dialog (tiếp)  Ý nghĩa hàm : • setTitle : thiết lập tiêu đề cho Dialog • setMessage: thiết lập nội dung cho Dialog • setIcon : thiết lập Icon • setPositiveButton, setNegativeButton thiết lập hiển thị nút chọn cho Dialog Chú ý đối số thứ hàm DialogInterface.OnClickListener View.OnClickListener • create() để tạo Dialog • show() để hiển thị Dialog Input Keyboard (2)Keyboard Actions: tạo nhãn riêng cho nút action  Sử dụng thuộc tính android:imeActionLabel để tạo nhãn riêng cho nút action muốn thực Input Keyboard (3)Keyboard Flags  Một vài flag sử dụng với thuộc tính android:imeOptions • flagNoFullscreen; • flagNavigatePrevious; • flagNavigateNext; • flagNoExtractUi; • flagNoAccessoryAction; • flagNoEnterAction; • flagForceAscii  Ví dụ: android:imeOptions="flagNoExtractUi“: làm cho hình nhập liệu không bị fullscreen Input Keyboard  Demo  Input Keyboard Search Tổng quan Search  Android cung cấp loại search: search dialog search widget  Tính sẵn có: • Tìm kiếm theo voice • Cung cấp từ gợi ý sau người dùng nhập vài ký tự • Cung cấp từ gợi ý dựa liệu xây dựng Search a)Tạo Searchable configuration  Tạo file searchable.xml thư mục /res/xml Cấu hình để gán thuộc tính như: voice search, search suggestion hint text cho hộp thoại search Ví dụ:

Ngày đăng: 06/03/2019, 09:33

Từ khóa liên quan

Mục lục

  • THIẾT KẾ GIAO DIỆN TRÊN ANDROID

  • Slide Number 2

  • Slide Number 3

  • Slide Number 4

  • Slide Number 5

  • Slide Number 6

  • Slide Number 7

  • Slide Number 8

  • Slide Number 9

  • Slide Number 10

  • Slide Number 11

  • Slide Number 12

  • Slide Number 13

  • Slide Number 14

  • Slide Number 15

  • Slide Number 16

  • Slide Number 17

  • Slide Number 18

  • Slide Number 19

  • Slide Number 20

Tài liệu cùng người dùng

Tài liệu liên quan