InputMethodService 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。
[Android.Runtime.Register("android/inputmethodservice/InputMethodService", DoNotGenerateAcw=true)]
public class InputMethodService : Android.InputMethodServices.AbstractInputMethodService
[<Android.Runtime.Register("android/inputmethodservice/InputMethodService", DoNotGenerateAcw=true)>]
type InputMethodService = class
inherit AbstractInputMethodService
- 繼承
- 屬性
備註
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 如需撰寫輸入方法的基本概念詳細資訊,請參閱基類 AbstractInputMethodService 和 InputMethod 介面。
除了一般服務生命週期方法之外,這個類別還會引進一些大部分子類別想要使用的新特定回呼:
<ul><li>#onInitializeInterface() 用於使用者介面初始化,特別是在服務執行時處理組態變更。 <li>#onBindInput 找出切換至新用戶端的相關信息。 <li>#onStartInput 從客戶端開始處理輸入工作階段。 <li>#onCreateInputView()、 #onCreateCandidatesView()和 #onCreateExtractTextView() ,用於非需求產生UI。 <li>#onStartInputView(EditorInfo, boolean) 處理輸入,從輸入區域輸入開始輸入。 </ul>
輸入法對於其運作方式具有重大自由裁量權: android.inputmethodservice.InputMethodService 提供標準 UI 元素的基本架構(輸入檢視、候選者檢視,以及以全螢幕模式執行),但由特定實作者決定如何使用它們。 例如,一個輸入方法可以使用鍵盤來實作輸入區域,另一個可以讓使用者繪製文字,而第三個輸入區域則沒有輸入區域(因此使用者看不到),而是接聽音訊並執行文字到語音轉換。
在此提供的實作中,所有這些元素都會放在 InputMethodService 所管理的單一視窗中。 它會在需要相關信息時執行回呼,並提供 API 以程式設計方式控制它們。 這些元素的版面設定已明確定義:
<ul><li>如果可用,軟輸入檢視會放在螢幕底部。 <li>候選檢視,如果目前顯示,則會放在軟輸入檢視上方。 <li> 如果未執行全螢幕,則會將應用程式移動或重設大小,使其位於這些檢視上方;如果執行全螢幕,視窗將會完全涵蓋應用程式,而其頂端部分會包含應用程式目前正在編輯之內容的擷取文字。 </ul>
“SoftInputView”><h3>Soft Input View</h3>
大部分輸入方法的核心是軟式輸入檢視。 這是大部分用戶互動發生的地方:按下軟鍵、繪圖字元,或輸入方法想要產生文字。 大部分實作只會有自己的檢視來執行所有這些工作,並在呼叫 時 #onCreateInputView() 傳回它的新實例。 此時,只要可以看到輸入檢視,您就會在該檢視中看到用戶互動,而且可以回呼 InputMethodService,視需要與應用程式互動。
在某些情況下,您想要決定是否應該向用戶顯示您的軟式輸入檢視。 這是藉由實作 #onEvaluateInputViewShown() ,根據它是否應該顯示在目前環境中,傳回 true 或 false 來完成。 如果您的狀態有任何變更可能會影響此情況,請呼叫 #updateInputViewShown() 以重新評估它。 除非有硬式鍵盤可供使用,否則默認實作一律會顯示輸入檢視,這是大部分輸入方法的適當行為。
“CandidatesView”><h3>候選項目檢視</h3>
當用戶產生原始文字時,輸入法通常會提供可供選取以供使用之文字的可能解譯清單。 這可透過候選檢視來完成,就像您實 #onCreateCandidatesView() 作的軟輸入檢視一樣,用來具現化實作候選 UI 的檢視。
候選檢視的管理與輸入檢視稍有不同,因為候選項目檢視往往較為暫時性,只有在使用者輸入目前文字的可能候選專案時才會顯示。 若要控制是否顯示候選取項目檢視,請使用 #setCandidatesViewShown(boolean)。 請注意,因為候選檢視通常會顯示和隱藏很多,所以它不會影響應用程式 UI 與軟輸入檢視相同:它永遠不會造成應用程式視窗重設大小,只會導致用戶視需要移動流覽目前的焦點。
“FullscreenMode”><h3>全螢幕模式</h3>
有時候您的輸入法 UI 太大而無法與應用程式 UI 整合,因此您只想接管畫面。 這可藉由切換至全螢幕模式來完成,導致輸入法視窗填滿整個畫面,並新增自己的「擷取文本」編輯器,向用戶顯示輸入的文字。 與其他 UI 元素不同,擷取編輯器有一個標準實作,您不需要變更。 編輯器會放在輸入和候選檢視上方的 IME 頂端。
與輸入檢視類似,您可以實 #onEvaluateFullscreenMode() 作 來根據目前環境中是否應該是全螢幕模式,控制 IME 是否以全螢幕模式執行, 以傳回 true 或 false。 如果您的狀態有任何變更可能會影響此情況,請呼叫 #updateFullscreenMode() 以重新評估它。 當螢幕處於橫向方向時,預設實作會選取全螢幕模式,這適用於具有重要輸入區域的大多數輸入方法。
在全螢幕模式中時,您有一些特殊需求,因為使用者看不到應用程式 UI。 特別是,您應該實 #onDisplayCompletions(CompletionInfo[]) 作 以顯示應用程式所產生的完成,通常是在候選人檢視中,就像您通常會顯示候選項目一樣。
“GeneratingText”><h3>產生文字</h3>
輸入法的主要部分當然是產生應用程式的文字。 這是透過對應用程式介面的呼叫android.view.inputmethod.InputConnection來完成,可從 擷取。#getCurrentInputConnection() 這個介面可讓您產生原始索引鍵事件,或者,如果目標支援它,請直接在候選項目和認可的文字字串中編輯。
透過 使用 方法擷取#getCurrentInputEditorInfo()的 android.view.inputmethod.EditorInfo 類別,即可找到目標預期和支援的相關信息。 其中最重要的部分是 android.view.inputmethod.EditorInfo#inputType EditorInfo.inputType;特別是,如果這是 android.view.inputmethod.EditorInfo#TYPE_NULL EditorInfo.TYPE_NULL,則目標不支援複雜的編輯,而且您只需要將原始索引鍵事件傳遞給它。 輸入法也會想要查看此處的其他值,例如偵測密碼模式、自動完成文字檢視、電話號碼輸入等。
當使用者在輸入目標之間切換時,您會收到 和#onStartInput(EditorInfo, boolean)的呼叫#onFinishInput()。 您可以使用這些來重設和初始化目前目標的輸入狀態。 例如,您通常會想要清除任何輸入狀態,並更新軟式鍵盤以適合新的 inputType。
的 android.inputmethodservice.InputMethodServiceJava 檔。
此頁面的部分是根據 Android 開放原始碼專案所建立和共用的工作進行修改,並根據 Creative Commons 2.5 屬性授權中所述的詞彙使用。
建構函式
| InputMethodService() | |
| InputMethodService(IntPtr, JniHandleOwnership) |
建立 JNI 物件的 Managed 表示法時使用的建構函式;由運行時間呼叫。 |
欄位
| AccessibilityService |
使用 搭配 |
| AccountService |
使用 搭配 |
| ActivityService |
使用 來 |
| AlarmService |
使用 搭配 |
| AppOpsService |
使用搭配 |
| AppSearchService |
使用 搭配 |
| AppwidgetService |
使用 搭配 |
| AudioService |
使用 搭配 |
| BatteryService |
使用搭配 |
| BindAllowActivityStarts |
已淘汰.
|
| BindExternalServiceLong |
的運作方式與 |
| BindNotPerceptible |
已淘汰.
旗標: |
| BindSharedIsolatedProcess |
已淘汰.
旗標: |
| BiometricService |
使用 來 |
| BlobStoreService |
使用 搭配 |
| BluetoothService |
使用 搭配 |
| BugreportService |
擷取 Bugreport 的服務。 (繼承來源 Context) |
| CameraService |
使用 來 |
| CaptioningService |
使用 搭配 |
| CarrierConfigService |
使用 搭配 |
| ClipboardService |
使用搭配 |
| CompanionDeviceService |
使用搭配 |
| ConnectivityDiagnosticsService |
使用 搭配 |
| ConnectivityService |
使用搭配 |
| ConsumerIrService |
使用 搭配 |
| CredentialService |
使用搭配 |
| CrossProfileAppsService |
使用 搭配 |
| DeviceIdDefault |
默認裝置識別碼,這是主要(非虛擬)裝置的標識碼。 (繼承來源 Context) |
| DeviceIdInvalid |
無效的裝置識別碼。 (繼承來源 Context) |
| DeviceLockService |
使用 搭配 |
| DevicePolicyService |
使用 搭配 |
| DisplayHashService |
使用搭配 |
| DisplayService |
使用 來 |
| DomainVerificationService |
使用搭配 |
| DownloadService |
使用 搭配 |
| DropboxService |
使用搭配 |
| EuiccService |
使用搭配 |
| FileIntegrityService |
使用 搭配 |
| FingerprintService |
使用搭配 |
| GameService |
使用 搭配 |
| GrammaticalInflectionService |
使用 搭配 |
| HardwarePropertiesService |
使用搭配 |
| HealthconnectService |
使用 搭配 |
| InputMethodService |
使用搭配 |
| InputService |
使用 來 |
| IpsecService |
使用 搭配 |
| JobSchedulerService |
使用 搭配 |
| KeyguardService |
使用 搭配 |
| LauncherAppsService |
使用 搭配 |
| LayoutInflaterService |
使用 搭配 |
| LocaleService |
使用 搭配 |
| LocationService |
使用 搭配 |
| MediaCommunicationService |
使用搭配 |
| MediaMetricsService |
使用 來 |
| MediaProjectionService |
使用 搭配 |
| MediaRouterService |
使用 搭配 |
| MediaSessionService |
使用搭配 |
| MidiService |
使用 搭配 |
| NetworkStatsService |
使用搭配 |
| NfcService |
使用 搭配 |
| NotificationService |
使用 搭配 |
| NsdService |
使用搭配 |
| OverlayService |
使用 搭配 |
| PeopleService |
使用 來 |
| PerformanceHintService |
使用 搭配 |
| PowerService |
使用 搭配 |
| PrintService |
|
| ReceiverExported |
已淘汰.
旗標 |
| ReceiverNotExported |
已淘汰.
旗標: |
| ReceiverVisibleToInstantApps |
已淘汰.
旗標: |
| RestrictionsService |
使用 搭配 |
| RoleService |
使用搭配 |
| SearchService |
使用 搭配 |
| SensorService |
使用 搭配 |
| ShortcutService |
使用搭配 |
| StatusBarService |
使用 來 |
| StopForegroundDetach |
已淘汰.
選取器 |
| StopForegroundLegacy |
的 |
| StopForegroundRemove |
已淘汰.
的 |
| StorageService |
使用搭配 |
| StorageStatsService |
使用搭配 |
| SystemHealthService |
使用 搭配 |
| TelecomService |
使用搭配 |
| TelephonyImsService |
使用 搭配 |
| TelephonyService |
使用 搭配 |
| TelephonySubscriptionService |
使用 搭配 |
| TextClassificationService |
使用 搭配 |
| TextServicesManagerService |
使用搭配 |
| TvInputService |
使用 來 |
| TvInteractiveAppService |
使用 搭配 |
| UiModeService |
使用 搭配 |
| UsageStatsService |
使用搭配 |
| UsbService |
使用 搭配 |
| UserService |
使用 搭配 |
| VibratorManagerService |
使用 搭配 |
| VibratorService |
使用 搭配 |
| VirtualDeviceService |
使用搭配 |
| VpnManagementService |
使用搭配 |
| WallpaperService |
使用 搭配 |
| WifiAwareService |
使用 搭配 |
| WifiP2pService |
使用 搭配 |
| WifiRttRangingService |
使用 搭配 |
| WifiService |
使用 搭配 |
| WindowService |
使用 搭配 |
屬性
| Application |
傳回擁有此服務的應用程式。 (繼承來源 Service) |
| ApplicationContext |
傳回目前進程之單一全域 Application 對象的內容。 (繼承來源 ContextWrapper) |
| ApplicationInfo |
傳回此內容套件的完整應用程式資訊。 (繼承來源 ContextWrapper) |
| Assets |
傳回應用程式套件的 AssetManager 實例。 (繼承來源 ContextWrapper) |
| AttributionSource |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Context) |
| AttributionTag |
屬性可用於複雜的應用程式中,以邏輯方式分隔應用程式的部分。 (繼承來源 Context) |
| BackDisposition |
擷取目前處置模式,指出預期的返回按鈕能供性。 -或- 設定配置模式,指出返回按鈕的預期能供性。 |
| BaseContext | (繼承來源 ContextWrapper) |
| CacheDir |
傳回檔案系統上應用程式特定快取目錄的絕對路徑。 (繼承來源 ContextWrapper) |
| CandidatesHiddenVisibility |
未顯示時,傳回候選檢視的可見性模式(或 |
| Class |
傳回這個 |
| ClassLoader |
傳回類別載入器,您可用來擷取此封裝中的類別。 (繼承來源 ContextWrapper) |
| CodeCacheDir |
傳回檔案系統上應用程式特定快取目錄的絕對路徑,該目錄是專為儲存快取的程式代碼所設計。 (繼承來源 ContextWrapper) |
| ContentResolver |
傳回應用程式套件的 ContentResolver 實例。 (繼承來源 ContextWrapper) |
| CurrentInputBinding |
針對輸入法傳回目前使用中的 InputBinding,如果沒有,則傳回 null。 |
| CurrentInputConnection |
擷取系結至輸入法的目前使用中 InputConnection,如果沒有,則為 null。 |
| CurrentInputEditorInfo | |
| CurrentInputStarted | |
| DataDir |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 ContextWrapper) |
| DeviceId |
取得此內容相關聯的裝置標識碼。 (繼承來源 Context) |
| Display |
取得與此內容相關聯的顯示。 (繼承來源 Context) |
| ExternalCacheDir |
傳回主要外部檔案系統上目錄的絕對路徑(也就是 ExternalStorageDirectory 應用程式可以放置其擁有之快取檔案的位置。 (繼承來源 ContextWrapper) |
| ExtractViewShown |
傳回是否顯示全螢幕擷取檢視。 -或- 控制所擷取文字區域的可見性。 |
| FilesDir |
傳回檔系統上用來儲存檔案 OpenFileOutput(String, FileCreationMode) 的目錄絕對路徑。 (繼承來源 ContextWrapper) |
| ForegroundServiceType |
如果服務已透過呼叫成為前景服務 |
| Handle |
基礎Android實例的句柄。 (繼承來源 Object) |
| InputMethodWindowRecommendedHeight |
為了傳回先前的 |
| IsDeviceProtectedStorage |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 ContextWrapper) |
| IsFullscreenMode |
傳回輸入法目前是否為<em>/em>,以<全螢幕模式執行。 |
| IsInputViewShown |
傳回軟輸入檢視是否為 <em>目前</em> 向用戶顯示。 |
| IsRestricted |
指出此內容是否受到限制。 (繼承來源 Context) |
| IsShowInputRequested |
如果系統要求顯示輸入檢視,則會傳回 true。 |
| IsUiContext |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 AbstractInputMethodService) |
| JniIdentityHashCode |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
| JniPeerMembers |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 |
| KeyDispatcherState |
傳 |
| LayoutInflater | |
| MainExecutor |
|
| MainLooper |
傳回目前進程之主線程的迴圈器。 (繼承來源 ContextWrapper) |
| MaxWidth |
傳回可用輸入法的最大寬度,以像素為單位。 |
| NoBackupFilesDir |
傳回檔案系統上目錄的絕對路徑,類似於 FilesDir。 (繼承來源 ContextWrapper) |
| ObbDir |
傳回此應用程式 OBB 檔案(如果有的話)可找到的主要外部記憶體目錄。 (繼承來源 ContextWrapper) |
| OpPackageName |
傳回應該用於 |
| PackageCodePath |
傳回此內容主要 Android 套件的完整路徑。 (繼承來源 ContextWrapper) |
| PackageManager |
傳回 PackageManager 實例以尋找全域套件資訊。 (繼承來源 ContextWrapper) |
| PackageName |
傳回此應用程式套件的名稱。 (繼承來源 ContextWrapper) |
| PackageResourcePath |
傳回此內容主要 Android 套件的完整路徑。 (繼承來源 ContextWrapper) |
| Params |
如果透過 建立此內容,則傳回此內容所建立 |
| PeerReference |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
| Resources |
傳回應用程式套件的 Resources 實例。 (繼承來源 ContextWrapper) |
| StylusHandwritingIdleTimeoutMax |
傳回與 搭配 使用 |
| StylusHandwritingSessionTimeout |
傳回持續時間,之後尚未收到新 |
| StylusHandwritingWindow |
會傳回手寫筆手寫筆跡視窗。 |
| Theme |
傳回與此內容相關聯的 Theme 物件。 (繼承來源 ContextWrapper) |
| ThresholdClass |
此 API 支援適用於 Android 的 Mono 基礎結構,並不適合直接從您的程式代碼使用。 |
| ThresholdType |
此 API 支援適用於 Android 的 Mono 基礎結構,並不適合直接從您的程式代碼使用。 |
| Wallpaper | (繼承來源 ContextWrapper) |
| WallpaperDesiredMinimumHeight | (繼承來源 ContextWrapper) |
| WallpaperDesiredMinimumWidth | (繼承來源 ContextWrapper) |
| Window | |
方法
明確介面實作
| IJavaPeerable.Disposed() |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
| IJavaPeerable.DisposeUnlessReferenced() |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
| IJavaPeerable.Finalized() |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
| IJavaPeerable.JniManagedPeerState |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
| IJavaPeerable.SetJniIdentityHashCode(Int32) |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
| IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
| IJavaPeerable.SetPeerReference(JniObjectReference) |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 (繼承來源 Object) |
擴充方法
| JavaCast<TResult>(IJavaObject) |
執行 Android 執行時間檢查的類型轉換。 |
| JavaCast<TResult>(IJavaObject) |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 |
| GetJniTypeName(IJavaPeerable) |
InputMethodService 提供 InputMethod 的標準實作,最終實作可以衍生自 和自定義。 |