2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
インプット メソッド エディタのサポート
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ディスプレイ固有の領域に対する更新内容は次のとおりです。
Android 10 は、デフォルト以外のディスプレイで実行されるアプリのソフトウェア キーボードをサポートしています。
デフォルト以外のディスプレイで実行されるアプリ
インプット メソッド エディタ(IME)のソフトウェア キーボードを表示するディスプレイには、さまざまなモードがあります。ソフトウェア キーボードは次のディスプレイに表示されます。
- フォーカスされているアプリが表示されているのと同じディスプレイ。
- フォーカスされているアプリがデフォルト以外のディスプレイで実行されているときのデフォルトのディスプレイ。
- ディスプレイがまったく表示されない。
使用するモードは、フォーカスされているアプリが表示されているディスプレイの設定に応じて決まります。詳しくは、以下をご覧ください。
WindowManager#setDisplayImePolicy()
WindowManager#getDisplayImePolicy()

図 1. ターゲット アプリと同じセカンダリ ディスプレイに表示された IME ソフトウェア キーボード
システムで使用される IME は 1 つですが、ユーザー フォーカスに合わせてディスプレイを切り替えることができます。Android 10 では、Google とサードパーティのすべての IME が自動的にレイアウトを修正し、作成された新しいディスプレイ サイズに合わせてサイズ変更する必要があります。
ディスプレイ A にアクティブな接続があり、ディスプレイ B の入力欄に入力フォーカスが必要な場合、次のフローが発生します。
- 新しい入力接続がディスプレイ B の入力欄から行われる。
- 接続が承認されるかどうかを
InputMethodManagerService
が確認する。
- IME のディスプレイが選択される。ディスプレイ B が IME の表示をサポートしており、IME を表示できる場合は、B が使用される。これに該当しない場合は、プライマリ デバイスのディスプレイが選択される。
- 選択されたディスプレイがディスプレイ A ではない場合は、接続が再確立される。
InputMethodService
が破棄されて再作成される。
セキュリティ制限
システムが所有していない仮想ディスプレイには IME は表示されません。これは、セキュリティ上の懸念として、悪意のあるアプリがシステム デコレーション サポートを有効にした仮想ディスプレイを作成し、サーフェスからユーザー機密情報(入力予測やカスタム背景など)を読み取る可能性があるためです。
実装
画面上の入力方法で説明されているように、Android 9 以前ではデフォルトの画面でのみ IME を使用できました。Android 10 以降では、フォーカスを切り替えて IME ウィンドウをセカンダリ ディスプレイに移動させることで、別のディスプレイの入力テキスト欄に切り替えることができます。
WindowManager
の実装では、入力方法ウィンドウ(ソフト キーボードが表示される IME ウィンドウ)と入力方法ターゲット(IME 入力が行われるウィンドウ)をトラッキングして IME の状態を管理します。
InputMethodManagerService
(IMMS)については、フォーカスを別のディスプレイに移動したときにディスプレイの変更を InputMethodService
(IMS)に反映して、ランタイムにキーボード レイアウトを再構成できる組み込みメカニズムは他にありません。
ディスプレイ間で IME ウィンドウを切り替えられるように、Android 10 には以下が実装されています。
- IME と入力ターゲット ウィンドウが、
DisplayContent#mInputMethodWindow
と DisplayContent#mInputMethodTarget
でディスプレイごとにトラッキングされるため、WindowManager(WM)は各ディスプレイの IME フォーカス状態を個別に管理できるようになりました。
- IMMS 側では、外部ディスプレイから
ViewRootImpl#handleWindowFocusChanged ->
InputMethodManager#onPostWindowFocus ->
IMMS#startInputOrWindowGainedFocus
経由でアプリ クライアントのフォーカス リクエストを受け取ると、最初に現在の入力方法サービスをバインド解除し、次にサービスを再バインドして、onServiceConnected()
の外部ディスプレイ用に新しい IME ウィンドウ トークンを再度割り当てます。
- IMS 側では、
IMS#attachToken
を受け取った後、次のフローが発生します。
InputMethodService#attachToken()
のサービス コンテキストの表示を更新するために、ContextImpl#updateDisplay
が呼び出されます。これによって呼び出された ViewGroup#addView()
が、現在のコンテキストを確認し、キーボードのレイアウトを修正してターゲット ディスプレイに合わせて調整します。
DisplayContent#setInputMethodWindowLocked()
が呼び出された後、実装は WindowProcessController
を使用してプロセスレベルのディスプレイ構成の変更を IME プロセスに送信し、リソースとディスプレイの指標をオーバーライドします。
InputMethodService
クライアントは、onConfigurationChanged()
と ViewGroup#addView()
の呼び出し後に、正しい構成と正しいディスプレイの指標を取得して入力ビューを再初期化します。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-10 UTC。
[[["わかりやすい","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-03-10 UTC。"],[],[],null,["# Input method editor support\n\nUpdates made to these display-specific areas are provided below:\n\n- [Apps running on a non-default display](/docs/core/display/multi_display/ime-support#non-default)\n- [Multi-session input method editor support](/docs/core/display/multi_display/ime-support#ime-multi)\n\nAndroid 10 supports\n[software keyboard](https://developer.android.com/guide/topics/text/creating-input-method)\nfor apps running on a non-default display.\n\nApps running on a non-default display\n-------------------------------------\n\nIn terms of which display shows the software keyboard of the Input Method Editor\n(IME), there are different modes. The software keyboard is shown on the:\n\n- *Same* display on which the focused app appears.\n- *Default* display while the focused app is running on a non-default display.\n- *No* display at all.\n\nThe system determines which mode to use based on the settings of the display\non which the focused app appears. For more details, see:\n\n- `WindowManager#setDisplayImePolicy()`\n- `WindowManager#getDisplayImePolicy()`\n\n**Figure 1.** IME software keyboard as it appears on secondary display,\nincluding target app\n\nThe system uses a single IME, but can shift between displays to follow\nuser focus. Android 10 automatically expects all first- and third-party IMEs to\nrevise the layout and resize according to the new display size when created.\n\nIf there's an active connection on display A, and an input field requests\ninput focus on display B, then the following flow occurs:\n\n1. A new input connection comes from the input field on display B.\n2. `InputMethodManagerService` checks if the connection should be approved.\n3. A display is selected for the IME. If display B supports showing the IME and is allowed to show it, then B is used. Otherwise, the primary device display is selected.\n4. If the selected display is not from display A, then the connection is re-established. `InputMethodService` is destroyed and then created again.\n\n### Security restriction\n\nThe system won't show an IME on virtual displays that aren't owned by the\nsystem. This is due to a security concern that a malicious app could create a\nvirtual display with enabled\n[system decorations support](/docs/core/display/multi_display/system-decorations)\nand read user-sensitive information from the surface, such as typing predictions\nand custom backgrounds.\n\n### Implementation\n\nIn Android 9 (and lower), the IME was only available on the default screen, as\ndescribed in [On-Screen\nInput methods](https://android-developers.googleblog.com/2009/04/updating-applications-for-on-screen.html). In Android 10 (and higher), a user can switch\nbetween different input text fields on different displays by switching focus,\nand the IME window moves to the secondary displays.\n\nThe implementation in `WindowManager` tracks the input method\nwindow (the IME window where the soft keyboard is drawn) and the input method\ntarget (the window where the IME input goes) to manage the IME state.\n\nFor `InputMethodManagerService` (IMMS), no other built-in mechanism can\npropagate the display change to `InputMethodService` (IMS) and\nreconfigure the keyboard layout at runtime when moving focus to another display.\n\nTo achieve the IME window switch between displays, Android\n10 implements the following:\n\n- The IME and input target window are now tracked per display in `DisplayContent#mInputMethodWindow` and `DisplayContent#mInputMethodTarget`, so that the WindowManager (WM) can manage the IME focus state independently of each display.\n- On the IMMS side, when an app client's focus request from the external display is received through `ViewRootImpl#handleWindowFocusChanged -\u003e\n InputMethodManager#onPostWindowFocus -\u003e\n IMMS#startInputOrWindowGainedFocus`, it first unbinds the current input method service and then rebinds the service to reattach the new IME window token for the external display in `onServiceConnected()`.\n- On the IMS side, after the `IMS#attachToken` is received, the following flow occurs:\n - `ContextImpl#updateDisplay` is called to update the service context's display in `InputMethodService#attachToken()`. This calls `ViewGroup#addView()` to revise the layout of the keyboard and adapt to the target display checking the current context.\n - After `DisplayContent#setInputMethodWindowLocked()` is called, the implementation sends process-level display configuration changes using the `WindowProcessController` to IME process to override resources and display metrics.\n - The `InputMethodService` client gets the correct configuration with the correct display metrics after `onConfigurationChanged()` and the `ViewGroup#addView()` call to reinitialize the input view."]]