Các phương pháp hay nhất cho lối tắt
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Khi thiết kế và tạo lối tắt của ứng dụng, hãy làm theo các nguyên tắc sau:
-
Làm theo các nguyên tắc thiết kế
-
Để lối tắt của ứng dụng nhất quán với lối tắt dùng cho các ứng dụng hệ thống, hãy làm theo Nguyên tắc thiết kế biểu tượng lối tắt ứng dụng.
-
Chỉ xuất bản 4 lối tắt riêng biệt
-
Mặc dù API hỗ trợ kết hợp tối đa 15 lối tắt tĩnh và động cho ứng dụng, nhưng bạn chỉ nên phát hành 4 lối tắt riêng biệt để cải thiện giao diện hình ảnh trong trình chạy.
Ngoài việc hiển thị lối tắt trên trình chạy, hãy sử dụng Thư viện tích hợp lối tắt của Google để hiển thị lối tắt trên các nền tảng của Google, chẳng hạn như Trợ lý Google. Thư viện này hỗ trợ đẩy số lượng lối tắt động không giới hạn. Nếu đang dùng thư viện này để đẩy một số lượng lớn lối tắt, bạn nên đặt rank
cho các lối tắt phải xuất hiện trong các trình chạy được hỗ trợ bằng cách gọi phương thức setRank()
.
-
Giới hạn độ dài đoạn mô tả cho lối tắt
-
Không gian trong trình đơn cho thấy lối tắt của ứng dụng trong trình chạy bị giới hạn. Khi có thể, hãy giới hạn độ dài của "nội dung mô tả ngắn" về lối tắt ở mức 10 ký tự và giới hạn độ dài của "nội dung mô tả dài" ở mức 25 ký tự.
Để biết thêm thông tin về nhãn cho các lối tắt tĩnh, vui lòng đọc bài viết Tuỳ chỉnh các giá trị thuộc tính.
Đối với các lối tắt động và được ghim, hãy đọc tài liệu tham khảo về setLongLabel()
và setShortLabel()
.
-
Duy trì nhật ký dụng lối tắt và thao tác
-
Đối với mỗi khẩu lệnh nhanh bạn tạo, hãy cân nhắc nhiều cách mà người dùng có thể thực hiện cùng một thao tác ngay trong ứng dụng. Hãy gọi reportShortcutUsed()
trong mỗi trường hợp này để trình chạy duy trì nhật ký chính xác về tần suất người dùng thực hiện các thao tác đại diện cho khẩu lệnh nhanh của bạn.
-
Chỉ cập nhật lối tắt khi ý nghĩa của lối tắt được giữ lại
-
Khi thay đổi lối tắt động và được ghim, chỉ gọi updateShortcuts()
khi thay đổi thông tin của lối tắt vẫn giữ nguyên ý nghĩa. Nếu không, hãy sử dụng một trong các phương thức sau, tuỳ thuộc vào loại lối tắt bạn đang tạo lại:
Ví dụ: nếu tạo lối tắt để điều hướng đến một siêu thị, bạn nên cập nhật lối tắt nếu tên của siêu thị thay đổi nhưng vị trí của siêu thị vẫn giữ nguyên. Tuy nhiên, nếu người dùng bắt đầu mua sắm tại một địa điểm siêu thị khác, bạn nên tạo một lối tắt mới.
-
Kiểm tra lối tắt linh hoạt mỗi khi bạn chạy ứng dụng
-
Lối tắt động không được lưu giữ khi người dùng khôi phục dữ liệu vào một thiết bị mới. Vì lý do này, bạn nên kiểm tra số lượng đối tượng mà getDynamicShortcuts()
trả về mỗi khi chạy ứng dụng và xuất bản lại lối tắt động nếu cần, như minh hoạ trên đoạn mã trong bài viết Sao lưu và khôi phục.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Best practices for shortcuts\n\nWhen designing and creating your app's shortcuts, follow these guidelines:\n\n\n**Follow the design guidelines**\n\n: To make your app's shortcuts visually consistent with the shortcuts used for system apps, follow\n the\n [App Shortcuts Icon Design Guidelines](/static/shareables/design/app-shortcuts-design-guidelines.pdf).\n\n\n**Publish only four distinct shortcuts**\n\n: Although the API supports a combination of up to 15 static and dynamic shortcuts for your app, we\n recommend that you publish only four distinct shortcuts, to improve their visual appearance in the\n launcher.\n\n In addition to displaying shortcuts on the launcher, use the\n [Google Shortcuts Integration Library](/develop/ui/views/launch/shortcuts/creating-shortcuts#gsi-library)\n to display shortcuts on Google surfaces such as Google Assistant. This library supports pushing an\n unlimited number of dynamic shortcuts. If you are using this library to push a large number of\n shortcuts, we recommend setting the `rank` of the shortcuts that must appear in supported\n launchers by calling the\n [](/reference/androidx/core/content/pm/ShortcutInfoCompat.Builder#setRank(int))`setRank()`\n method.\n\n\n**Limit shortcut description length**\n\n: The space in the menu that shows your app's shortcuts in the launcher is limited. When possible,\n limit the length of the \"short description\" of a shortcut to 10 characters and limit the length of\n the \"long description\" to 25 characters.\n\n For more information about labels for static shortcuts, read\n [Customize attribute values](/guide/topics/ui/shortcuts/creating-shortcuts#attribute-values).\n For dynamic and pinned shortcuts, read the reference documentation on\n [setLongLabel()](/reference/androidx/core/content/pm/ShortcutInfoCompat.Builder#setLongLabel(java.lang.CharSequence))\n and\n [setShortLabel()](/reference/androidx/core/content/pm/ShortcutInfoCompat.Builder#setShortLabel(java.lang.CharSequence)).\n\n\n**Maintain shortcut and action usage history**\n\n: For each shortcut you create, consider the different ways a user can accomplish the same task\n directly within your app. Call\n [reportShortcutUsed()](/reference/androidx/core/content/pm/ShortcutManagerCompat#reportShortcutUsed(android.content.Context,%20java.lang.String))\n in each of these situations so that the launcher maintains an accurate history of how frequently a\n user performs the actions representing your shortcuts.\n\n\n**Update shortcuts only when their meaning is retained**\n\n: When changing dynamic and pinned shortcuts, only call\n [updateShortcuts()](/reference/androidx/core/content/pm/ShortcutManagerCompat#updateShortcuts(android.content.Context,%20java.util.List%3Candroidx.core.content.pm.ShortcutInfoCompat%3E))\n when changing the information of a shortcut that retains its meaning. Otherwise, use one of the\n following methods, depending on the type of shortcut you're recreating:\n\n - Dynamic shortcuts: [pushDynamicShortcut()](/reference/androidx/core/content/pm/ShortcutManagerCompat#pushDynamicShortcut(android.content.Context,%20androidx.core.content.pm.ShortcutInfoCompat)).\n - Pinned shortcuts: [requestPinShortcut()](/reference/androidx/core/content/pm/ShortcutManagerCompat#requestPinShortcut(android.content.Context,%20androidx.core.content.pm.ShortcutInfoCompat,%20android.content.IntentSender)).\n\n For example, if you create a shortcut for navigating to a supermarket, it is appropriate to\n update the shortcut if the name of the supermarket changes but its location stays the same. If the\n user begins shopping at a different supermarket location, however, it's better to create a new\n shortcut.\n\n\n**Check dynamic shortcuts whenever you launch your app**\n\n: Dynamic shortcuts aren't preserved when the user restores their data onto a new device. For this\n reason, we recommend that you check the number of objects returned by\n [getDynamicShortcuts()](/reference/androidx/core/content/pm/ShortcutManagerCompat#getDynamicShortcuts(android.content.Context))\n each time you launch your app and re-publish dynamic shortcuts as needed, as shown in the code\n snippet in\n [Backup and restore](/guide/topics/ui/shortcuts/managing-shortcuts#backup-restore)."]]