Android 中文api (81)——InputMethod [输入法]
前言
本章內容是android.view.inputmethod.InputMethod,為輸入法相關章節,版本為Android 2.3 r1,翻譯來自"六必治",歡迎大家訪問他的博客:http://www.cnblogs.com/zcmky/,再次感謝"六必治" !期待你加入Android API 中文的翻譯,聯系我over140@gmail.com。
?
聲明
歡迎轉載,但請保留文章原始出處:)
?
農民伯伯:http://over140.blog.51cto.com/
Android中文翻譯組:http://code.taobao.org/project/view/404/
?
?
正文
一、結構
public interface InputMethod extends Object
????????
android.view.inputmethod.InputMethod
?
間接子類
AbstractInputMethodService.AbstractInputMethodImpl, InputMethodService.InputMethodImpl
?
二、類概述
InputMethod接口代表了輸入法,它可生成按鍵事件,生成文本,如數字,email地址,CJK字符,其它語言字符等等。在處理輸入事件時,將文本返回至需要文本輸入的應用程序。InputMethodManager可得到更多關于架構的信息。
應用程序通常不使用這個接口本身,而是依靠TextView 和 EditText提供的標準交互。
輸入法實現通常為InputMethodService及其子類的派生。在實現輸入法時,包含它的服務控件必須提供SERVICE_META_DATA元數據字段,該元數據字段聯接至一包含輸入法細節的XML資源。所有輸入法也必定要求客戶端包含BIND_INPUT_METHOD以便與服務控件交互。如果不這樣,系統將無法使用輸入法,因其無法確認是否完整。
InputMethod接口實際上分為兩部分:接口是輸入法的最高級接口,提供所有的訪問,只有系統能訪問(需要BIND_INPUT_METHOD權限)。另外調用方法createSession(android.view.inputmethod.InputMethod.SessionCallback)可實例化InputMethodSession副接口,用于與客戶端通訊。?
三、內部類
???????? interface ???????? InputMethod.SessionCallback
?
四、常量
public static final String SERVICE_INTERFACE
接口名字,實現輸入法的服務應說明它支持輸入法,也就是它將用于意向過濾器(intent filter)。服務還需要BIND_INPUT_METHOD權限,這樣應用程序不會濫用它。
常量值: "android.view.InputMethod"
?
public static final String SERVICE_META_DATA
輸入法通過此名字發布其自身信息。此元數據必須引用一個包含< input-method>標簽的XML資源。
常量值: "android.view.im"
?
public static final int SHOW_EXPLICIT
用于showSoftInput(int, ResultReceiver)的標志:它表示用戶顯式地要求其(軟鍵盤)顯示。如果沒有設置,系統決定可能是一個好主意,顯示輸入法在用戶界面上的導航操作。
常量值: 1 (0x00000001)
?
public static final int SHOW_FORCED
標志用于showSoftInput(int, ResultReceiver):表明用戶強制其(軟鍵盤)顯示。如設置,輸入法保持可見直至用戶在UI上取消。
常量值: 2 (0x00000002)
?
五、公共方法
public abstract void attachToken (IBinder token)
輸入法創建后首先被調用,它提供一個與系統服務會話的唯一令牌。它需要通過服務識別輸入法從而驗證其操作。令牌不能傳遞給應用程序,因其取得了應用程序不應得到的特殊權限。
注意:為避免惡意客戶端傷害,你應只接收第一個令牌。其后可能來自客戶端。
?
public abstract void bindInput (InputBinding binding)
將輸入法與新的應用程序環境綁定,以便稍后啟動、停止輸入處理。通常在應用程序第一次啟用輸入法時調用此方法。
參數
binding ?? 與輸入法綁定的應用程序窗口信息。
參見
?? ???????????????????? InputBinding
?????????????????? unbindInput()
?
public abstract void createSession (InputMethod.SessionCallback callback)
創建一個新的InputMethodSession,它可處理客戶應用程序與輸入法的交互。你可以隨后用revokeSession(InputMethodSession)銷毀會話,這樣就不會有任何客戶端使用它。
參數
callback 新創建會話調用的接口。
?
public abstract void hideSoftInput (int flags, ResultReceiver resultReceiver)
將輸入法的軟鍵盤(soft input)部分對用戶隱藏。
參數
flags ?????? 顯示要求的附加信息。當前總是0。
resultReceiver ?向要求顯示的客戶端通知結果。其結果可能為InputMethodManager.RESULT_UNCHANGED_SHOWN, InputMethodManager.RESULT_UNCHANGED_HIDDEN,InputMethodManager.RESULT_SHOWN, 或 InputMethodManager.RESULT_HIDDEN
?
public abstract void restartInput (InputConnection inputConnection, EditorInfo attribute)
輸入法需重置時調用此方法。
通常輸入焦點從一個文本框移至另一個時調用此方法。
參數
inputConnection ??? 可選,確定與文本框通訊的輸入通訊通道;如為空,你使用通常綁定的輸入通訊通道。
attribute ???????? 文本框(通常是EditText)需要輸入的屬性
參見
??????????????????????????? EditorInfo
?
public abstract void revokeSession (InputMethodSession session)
關閉并銷毀先前由createSession(android.view.inputmethod.InputMethod.SessionCallback)創建的會話。調用后,會話不再有效,對其的調用將失敗。
參數
session ?先前由SessionCallback.sessionCreated()提供的InputMethodSession將被吊銷。
?
public abstract void setSessionEnabled (InputMethodSession session, boolean enabled).
控制某特定輸入法會話是否激活。
參數
session ?先前由SessionCallback.sessionCreated()提供的InputMethodSession將改變。
?
public abstract void showSoftInput (int flags, ResultReceiver resultReceiver)
將輸入法的軟鍵盤(soft input)部分對用戶顯示。
參數
flags ?提供顯示要求的附加信息。當前為0或設置SHOW_EXPLICIT 位。
resultReceiver ?向要求顯示的客戶端通知結果。其結果可能為InputMethodManager.RESULT_UNCHANGED_SHOWN, InputMethodManager.RESULT_UNCHANGED_HIDDEN,InputMethodManager.RESULT_SHOWN, 或 InputMethodManager.RESULT_HIDDEN
?
public abstract void startInput (InputConnection inputConnection, EditorInfo info)
應用程序開始接收文本,輸入法準備好為應用程序處理接收事件并返回文本時調用本方法。
參數
inputConnection ??? 可選,確定與文本框通訊的輸入通訊通道;如為空,你使用通常綁定的輸入通訊通道。
info ?需要輸入的文本框(通常是EditText)信息。
參見
?? ???????????????????? EditorInfo
?
public abstract void unbindInput ()
???????? 解除與應用程序的綁定,先前由bindInput(InputBinding)設定的信息對當前輸入法無效時調用。
通常在應用程序變為非前臺調用。?
六、補充
?
文章精選
在Android中創建一種新的輸入法(Creating an Input Method)
Android input method panel control
通過一個SoftKeyboard例子(可以看看博客里的其他幾篇文章)
Android IMF的一處瑕疵
Android IMF輸入法總結
為 Android 平臺開發一個輸入法
Android IMF學習筆記一
Android Framework系列之IMF(一)
Android Framework系列之IMF(二)
Android Framework系列之IMF(三)
轉載于:https://blog.51cto.com/over140/582435
總結
以上是生活随笔為你收集整理的Android 中文api (81)——InputMethod [输入法]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OOP的核心思想是什么?请简述你对OOP
- 下一篇: 使用云存储解决方案,主要有哪些优势