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() 用於使用者介面初始化,特別是在服務執行時處理設定變更。
<
>
#onBindInput Li 想了解換新客戶的事。
<
>
#onStartInput LI 處理一個從客戶端開始的輸入會話。
<li>#onCreateInputView(), #onCreateCandidatesView(), 以及 #onCreateExtractTextView() 用於非需求產生的 UI。
<
>
#onStartInputView(EditorInfo, boolean) LI 來處理從 IME 輸入區域開始的輸入。
</ul>
輸入法在工作方式上擁有相當大的自由裁量權:它 android.inputmethodservice.InputMethodService 為標準 UI 元素(輸入檢視、候選檢視及全螢幕模式)提供基本框架,但如何使用則由特定實作者決定。 例如,一種輸入法可以實作一個帶有鍵盤的輸入區,另一種則允許使用者繪製文字,而第三種則可能沒有輸入區(因此使用者看不到),而是透過聆聽音訊並進行文字轉語音轉換。
在此提供的實作中,所有這些元素都被放在由 InputMethodService 管理的單一視窗中。 它會在需要相關資訊時執行回調,並提供程式化控制的 API。 這些元素的配置有明確定義:
<ul><li>軟輸入視圖(如有)會放在螢幕底部。 <li>候選人視圖(若目前顯示)會被置於軟輸入視圖之上。 <如果>不是全螢幕,應用程式會移動或調整大小以高於這些視圖;如果全螢幕,視窗會完全覆蓋應用程式,其上方會包含應用程式目前正在編輯內容的擷取文字。 </ul>
「SoftInputView」><h3>軟輸入視圖</h3>
大多數輸入法的核心是軟輸入視圖。 大多數使用者互動都發生在這裡:按軟鍵、畫字元,或輸入方式想用的其他方式產生文字。 大多數實作會用自己的視圖來完成所有這些工作,並在被呼叫時 #onCreateInputView() 回傳新的實例。 此時,只要輸入檢視可見,你就能看到使用者互動,並可呼叫 InputMethodService 與應用程式互動。
有些情況下,你會想決定是否要把軟輸入視圖顯示給使用者。 這是透過實作 #onEvaluateInputViewShown() 回傳真或假,根據是否應在當前環境中顯示來實現。 如果你所在州有變動,可能會影響這個狀況,請打電話 #updateInputViewShown() 重新評估。 預設實作總是顯示輸入視圖,除非有硬鍵盤可用,這對大多數輸入方式來說是適當的行為。
「候選人視圖」><h3>候選人視圖</h3>
通常在使用者產生原始文字時,輸入方法會提供一份可選擇使用的可能詮釋清單。 這是透過候選人視圖實現的,就像你實作 #onCreateCandidatesView() 軟輸入視圖來實例自己的視圖,實作候選人的使用者介面一樣。
候選視圖的管理與輸入視圖略有不同,因為候選視圖較為短暫,僅在使用者輸入當前文本可能有候選時才會顯示。 要控制候選人的視角是否被顯示,請使用 #setCandidatesViewShown(boolean)。 請注意,候選視圖通常會被顯示和隱藏,因此它不會像軟輸入視圖那樣影響應用程式的使用者介面:它不會讓應用程式視窗變大,只會在需要時平移視窗讓使用者看到當前焦點。
「全螢幕模式」><h3>全螢幕模式</h3>
有時候你的輸入法介面太大,無法整合到應用程式介面,所以你只想接管整個螢幕。 這是透過切換到全螢幕模式來實現的,使輸入法視窗填滿整個螢幕,並新增自己的「擷取文字」編輯器,顯示正在輸入的文字。 與其他 UI 元素不同,擷取編輯器有標準實作,你不需要更改。 編輯器被置於 IME 的頂端,位於輸入與候選人檢視之上。
類似輸入檢視,你可以透過實作 #onEvaluateFullscreenMode() 回傳真或假,來控制 IME 是否以全螢幕模式運行,這取決於它在當前環境中是否應該是全螢幕。 如果你所在州有變動,可能會影響這個狀況,請打電話 #updateFullscreenMode() 重新評估。 預設實作在螢幕橫向時會選擇全螢幕模式,這對於大多數有顯著輸入區域的輸入方法來說是適當的行為。
在全螢幕模式下,使用者會看到應用程式介面,因此有些特殊需求。 特別是,你應該實作 #onDisplayCompletions(CompletionInfo[]) 顯示申請所產生的完成紀錄,通常在候選人的視圖中,就像你平常展示候選人一樣。
「生成文本」><h3>生成文字</h3>
IME 的關鍵部分當然是產生應用程式所需的文字。 這是透過呼叫 android.view.inputmethod.InputConnection 應用程式介面來完成的,該介面可從 #getCurrentInputConnection()中取得。 此介面允許你產生原始金鑰事件,或若目標支援,直接編輯候選字串與已提交文本。
關於目標的期望與支援資訊可透過 android.view.inputmethod.EditorInfo 類別找到,並透過方法檢索 #getCurrentInputEditorInfo() 。 其中最重要的是 android.view.inputmethod.EditorInfo#inputType EditorInfo.inputType;特別是,如果是 android.view.inputmethod.EditorInfo#TYPE_NULL EditorInfo.TYPE_NULL,表示目標不支援複雜編輯,你只需將原始的金鑰事件送入。 輸入法還會想查看其他數值,例如偵測密碼模式、自動完成文字檢視、電話號碼輸入等。
當使用者在輸入目標間切換時,你會收到指向 #onFinishInput() 和 #onStartInput(EditorInfo, boolean)的呼叫。 你可以用這些來重置並初始化目前目標的輸入狀態。 例如,你常常會想要清除任何輸入狀態,並更新軟鍵盤以符合新的 inputType。
Java 文件 android.inputmethodservice.InputMethodService。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。
建構函式
| 名稱 | Description |
|---|---|
| InputMethodService() | |
| InputMethodService(IntPtr, JniHandleOwnership) |
用於建立 JNI 物件受管理表示的建構器;由執行時呼叫。 |
欄位
| 名稱 | Description |
|---|---|
| AccessibilityService |
使用 with |
| AccountService |
使用 with |
| ActivityService |
使用 來 |
| AdvancedProtectionService |
使用 以 |
| AlarmService |
使用 with |
| AppFunctionService |
用 來 |
| AppOpsService |
使用 with |
| AppSearchService |
用 來 |
| AppwidgetService |
使用 with |
| AudioService |
使用來 |
| BatteryService |
用 來 |
| BindAllowActivityStarts |
已淘汰.
標記 |
| BindExternalServiceLong |
其運作方式與 相同 |
| BindNotPerceptible |
已淘汰.
標記: |
| BindPackageIsolatedProcess |
已淘汰.
標記 |
| BindSharedIsolatedProcess |
已淘汰.
標記為 |
| BiometricService |
用 with |
| BlobStoreService |
使用 with |
| BluetoothService |
用 來 |
| BugreportService |
服務用來擷取錯誤報告。 (繼承來源 Context) |
| CameraService |
用 來 |
| CaptioningService |
使用 with |
| CarrierConfigService |
使用 來 |
| ClipboardService |
使用 with |
| CompanionDeviceService |
使用 with |
| ConnectivityDiagnosticsService |
使用來 |
| ConnectivityService |
使用 with |
| ConsumerIrService |
使用時 |
| ContactKeysService |
使用來 |
| CredentialService |
使用 with |
| CrossProfileAppsService |
使用 with |
| DeviceIdDefault |
預設裝置 ID,即主要(非虛擬)裝置的 ID。 (繼承來源 Context) |
| DeviceIdInvalid |
裝置 ID 無效。 (繼承來源 Context) |
| DeviceLockService |
使用 with |
| DevicePolicyService |
使用 with |
| DisplayHashService |
使用 to |
| DisplayService |
使用 with |
| DomainVerificationService |
使用 to |
| DownloadService |
使用 with |
| DropboxService |
用 來 |
| EuiccService |
用 來 |
| FileIntegrityService |
使用 以 |
| FingerprintService |
使用來 |
| GameService |
使用 with |
| GrammaticalInflectionService |
使用 with |
| HardwarePropertiesService |
使用 with |
| HealthconnectService |
使用 with |
| InputMethodService |
使用 with |
| InputService |
使用 來 |
| IpsecService |
使用 with |
| JobSchedulerService |
用 with |
| KeyguardService |
用 來 |
| KeystoreService |
使用 with |
| LauncherAppsService |
使用 with |
| LayoutInflaterService |
在此語境下,使用 with |
| LocaleService |
使用 with |
| LocationService |
使用 with |
| MediaCommunicationService |
使用 來 |
| MediaMetricsService |
使用 with |
| MediaProjectionService |
使用 with |
| MediaQualityService |
使用 with |
| MediaRouterService |
使用 with |
| MediaSessionService |
使用 with |
| MidiService |
使用 with |
| NetworkStatsService |
用 來 |
| NfcService |
使用 with |
| NotificationService |
使用 with |
| NsdService |
使用 with |
| OverlayService |
用 來 |
| PeopleService |
使用 with |
| PerformanceHintService |
使用 來 |
| PersistentDataBlockService |
用 來 |
| PowerService |
用 來 |
| PrintService |
|
| ProfilingService |
使用 以 |
| ReceiverExported |
已淘汰.
標記: |
| ReceiverNotExported |
已淘汰.
標記 |
| ReceiverVisibleToInstantApps |
已淘汰.
標記: |
| RestrictionsService |
使用 with |
| RoleService |
使用 with |
| SatelliteService |
使用 with |
| SearchService |
使用 with |
| SecurityStateService |
使用 with |
| SensorService |
用 來 |
| ShortcutService |
用 with |
| StatusBarService |
用 來 |
| StopForegroundDetach |
已淘汰.
選擇器 : |
| StopForegroundLegacy |
選擇器 : |
| StopForegroundRemove |
已淘汰.
選擇器 |
| StorageService |
使用 來 |
| StorageStatsService |
使用 with |
| SystemHealthService |
用 來 |
| TelecomService |
使用 with |
| TelephonyImsService |
使用 以 |
| TelephonyService |
使用 來 |
| TelephonySubscriptionService |
使用 with |
| TetheringService |
使用 with |
| TextClassificationService |
使用 with |
| TextServicesManagerService |
使用 with |
| TvAdService |
使用 with |
| TvInputService |
用 來 |
| TvInteractiveAppService |
使用 with |
| UiModeService |
用 來 |
| UsageStatsService |
用 來 |
| UsbService |
用 來 |
| UserService |
使用 with |
| VibratorManagerService |
使用來 |
| VibratorService |
使用來 |
| VirtualDeviceService |
使用 with |
| VpnManagementService |
使用 with |
| WallpaperService |
用 with |
| WifiAwareService |
使用 with |
| WifiP2pService |
使用 with |
| WifiRttRangingService |
用 with |
| WifiService |
使用 with |
| WindowService |
使用 with |
屬性
| 名稱 | Description |
|---|---|
| Application |
回傳擁有這項服務的應用程式。 (繼承來源 Service) |
| ApplicationContext |
回傳目前程序單一全域應用程式物件的上下文。 (繼承來源 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 |
會取得該上下文所關聯的裝置 ID。 (繼承來源 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>還是>顯示給使用者。 |
| IsRestricted |
表示此上下文是否受限。 (繼承來源 Context) |
| IsShowInputRequested |
如果我們被要求顯示輸入視圖,則會回傳為真。 |
| IsUiContext |
InputMethodService 提供標準的 InputMethod 實作,最終實作可從此衍生並自訂。 (繼承來源 AbstractInputMethodService) |
| JniIdentityHashCode |
InputMethodService 提供標準的 InputMethod 實作,最終實作可從此衍生並自訂。 (繼承來源 Object) |
| JniPeerMembers |
InputMethodService 提供標準的 InputMethod 實作,最終實作可從此衍生並自訂。 |
| KeyDispatcherState |
回傳用於處理目標應用程式事件的全域 |
| LayoutInflater | |
| MainExecutor |
回傳 和 |
| MainLooper |
回傳當前程序主執行緒的 Looper。 (繼承來源 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 |
回傳與此上下文相關的主題物件。 (繼承來源 ContextWrapper) |
| ThresholdClass |
此 API 支援 Mono for Android 基礎架構,並非直接從你的程式碼中使用。 |
| ThresholdType |
此 API 支援 Mono for Android 基礎架構,並非直接從你的程式碼中使用。 |
| Wallpaper | (繼承來源 ContextWrapper) |
| WallpaperDesiredMinimumHeight | (繼承來源 ContextWrapper) |
| WallpaperDesiredMinimumWidth | (繼承來源 ContextWrapper) |
| Window | |
方法
明確介面實作
| 名稱 | Description |
|---|---|
| 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) |
擴充方法
| 名稱 | Description |
|---|---|
| GetJniTypeName(IJavaPeerable) |
取得實例 |
| JavaAs<TResult>(IJavaPeerable) |
試著強制 |
| JavaCast<TResult>(IJavaObject) |
執行 Android 執行時檢查型別轉換。 |
| JavaCast<TResult>(IJavaObject) |
InputMethodService 提供標準的 InputMethod 實作,最終實作可從此衍生並自訂。 |
| TryJavaCast<TResult>(IJavaPeerable, TResult) |
試著強制 |