從 Android 11 開始,鍵盤及其他輸入法編輯器 (簡稱「IME」) 可在建議列或類似容器中以內嵌方式顯示自動填入建議,而非由系統在選單中顯示這些建議。這些自動填入建議可能包含密碼或信用卡資訊等私人資料,因此在使用者選擇某項建議之前,系統會向 IME 隱藏建議。如要充分利用這項功能,請更新 IME 和自動填入服務,例如密碼管理工具。如果 IME 或自動填入服務不支援內嵌自動填入功能,選單中就會顯示建議,如同在 Android 11 以下版本中一樣。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-27 (世界標準時間)。"],[],[],null,["Beginning in Android 11, keyboards and other input-method editors\n(*IMEs* ) can display autofill suggestions inline, in a suggestion strip, or\nsomething similar instead of the system displaying suggestions in a menu. Since\nthese autofill suggestions can contain private data, such as passwords or\ncredit-card information, the suggestions are hidden from the IME until the user\nselects one. Update IMEs and autofill services, such as password managers, to\nmake use of this feature. If an IME or a autofill service doesn't support inline\nautofill, suggestions are shown in a menu, as in [versions earlier than\nAndroid 11](/guide/topics/text/autofill#guides).\n\nWorkflow\n\nIn this flow, *IME* means the current keyboard or other input editor, and\n*suggestion provider* means the appropriate provider of the autofill suggestion.\nDepending on the input field and the user's settings, the suggestion provider\nmight be the platform or an autofill service.\n\n1. The user focuses on an input field that triggers autofill, like a password or\n credit-card input field.\n\n2. The platform queries the current IME and the appropriate suggestion provider\n to see whether they support inline autofill. If either the IME or the\n suggestion provider doesn't support inline autofill, the suggestion is shown\n in a menu, as on Android 10 and lower.\n\n3. The platform asks the IME to provide a *suggestion request* . This suggestion\n request specifies the maximum number of suggestions to be displayed and also\n provides *presentation specs* for each suggestion. The presentation specs\n specify things like maximum size, text size, colors, and font data, letting\n the suggestion provider match the look and feel of the IME.\n\n4. The platform asks the suggestion provider to provide up to the requested\n number of suggestions. Each suggestion includes a callback to inflate a\n `View` containing the suggestion's UI.\n\n5. The platform informs the IME that suggestions are ready. The IME displays\n the suggestions by calling the callback method to inflate each suggestion's\n `View`. To protect the user's private information, the IME does *not* see\n what the suggestions are at this stage.\n\n6. If the user selects one of the suggestions, the IME is informed the same way\n as if the user picks a suggestion from a system menu.\n\nThe following sections describe how to configure your IME or autofill service to\nsupport inline autofill.\n\nConfigure IMEs to support inline autofill\n\nThis section describes how to configure your IME to support inline autofill. If\nyour IME doesn't support inline autofill, the platform defaults to showing\nautofill suggestions in a menu.\n\nYour IME must [set the `supportsInlinedSuggestions` attribute to\n`true`](/guide/topics/text/creating-input-method): \n\n \u003cinput-method\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:supportsInlineSuggestions=\"true\"/\u003e\n\nWhen the platform needs an autofill suggestion, it calls your IME's\n[`InputMethodService.onCreateInlineSuggestionsRequest()`](/reference/android/inputmethodservice/InputMethodService#onCreateInlineSuggestionsRequest(android.os.Bundle))\nmethod. You must implement this method. Return an\n[`InlineSuggestionsRequest`](/reference/android/view/inputmethod/InlineSuggestionsRequest)\nspecifying the following:\n\n- How many suggestions your IME wants.\n- An\n [`InlinePresentationSpec`](/reference/android/widget/inline/InlinePresentationSpec)\n for each suggestion, defining how the suggestion must be presented.\n\n | **Note:** If you provide fewer presentation specs than the number of suggestions requested, the last spec is used for all the excess suggestions. This means, for example, that if you provide only a single presentation spec, the suggestion provider uses that spec for all the suggestions.\n\nWhen the platform has suggestions, it calls your IME's\n[`onInlineSuggestionsResponse()`](/reference/android/inputmethodservice/InputMethodService#onInlineSuggestionsResponse(android.view.inputmethod.InlineSuggestionsResponse))\nmethod, passing an\n[`InlineSuggestionsResponse`](/reference/android/view/inputmethod/InlineSuggestionsResponse)\ncontaining the suggestions. You must implement this method. In your\nimplementation, call\n[`InlineSuggestionsResponse.getInlineSuggestions()`](/reference/android/view/inputmethod/InlineSuggestionsResponse#getInlineSuggestions())\nto get the list of suggestions, then inflate each suggestion by calling its\n[`InlineSuggestion.inflate()`](/reference/android/view/inputmethod/InlineSuggestion#inflate(android.content.Context,%20android.util.Size,%20java.util.concurrent.Executor,%20java.util.function.Consumer%3Candroid.widget.inline.InlineContentView%3E))\nmethod.\n\nConfigure autofill services to support inline autofill\n\nThis section describes how to configure your autofill service to support inline\nautofill. If your app doesn't support inline autofill, the platform defaults to\nshowing its autofill suggestions in a menu.\n\nYour autofill service must [set the `supportsInlinedSuggestions` attribute to\n`true`](/guide/topics/text/autofill-services): \n\n \u003cautofill-service\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:supportsInlineSuggestions=\"true\"/\u003e\n\nWhen the IME needs autofill suggestions, the platform calls your autofill\nservice's\n[`onFillRequest()`](/reference/android/service/autofill/AutofillService#onFillRequest(android.service.autofill.FillRequest,%20android.os.CancellationSignal,%20android.service.autofill.FillCallback))\nmethod, just as it does in versions below Android 11. However, your\nservice must call the passed `FillRequest` object's\n[`getInlineSuggestionsRequest()`](/reference/android/service/autofill/FillRequest#getInlineSuggestionsRequest())\nmethod to get the `InlineSuggestionsRequest` created by the IME. The\n`InlineSuggestionsRequest` specifies how many inline suggestions are needed and\nhow each one must be presented. If the IME doesn't support inline suggestions,\nthe method returns `null`.\n\nYour autofill service creates\n[`InlinePresentation`](/reference/android/service/autofill/InlinePresentation)\nobjects, up to the maximum number requested in the `InlineSuggestionsRequest`.\nYour presentations must obey the size constraints specified by the\n`InlineSuggestionsRequest`. To return your suggestions to the IME, call\n[`Dataset.Builder.setValue()`](/reference/android/service/autofill/Dataset.Builder#setValue(android.view.autofill.AutofillId,%20android.view.autofill.AutofillValue,%20java.util.regex.Pattern,%20android.widget.RemoteViews,%20android.service.autofill.InlinePresentation))\nonce for each suggestion. Android 11 provides versions of\n`Dataset.Builder.setValue()` to support inline suggestions.\n| **Note:** Although the IME is supposed to use the suggestions your service provides, this function isn't guaranteed."]]