天天看點

Android 中文api (81)——InputMethod [輸入法]

正文

  一、結構

public interface InputMethod extends Object

android.view.inputmethod.InputMethod

間接子類

  二、類概述

  應用程式通常不使用這個接口本身,而是依靠TextView 和 EditText提供的标準互動。

  三、内部類

         interface          InputMethod.SessionCallback

  四、常量

  public static final String SERVICE_INTERFACE

  常量值: "android.view.InputMethod"

  public static final String SERVICE_META_DATA

  常量值: "android.view.im"

  public static final int SHOW_EXPLICIT

  常量值: 1 (0x00000001)

  public static final int SHOW_FORCED

  常量值: 2 (0x00000002)

  五、公共方法

  public abstract void attachToken (IBinder token)

  輸入法建立後首先被調用,它提供一個與系統服務會話的唯一令牌。它需要通過服務識别輸入法進而驗證其操作。令牌不能傳遞給應用程式,因其取得了應用程式不應得到的特殊權限。

  注意:為避免惡意用戶端傷害,你應隻接收第一個令牌。其後可能來自用戶端。

  public abstract void bindInput (InputBinding binding)

  将輸入法與新的應用程式環境綁定,以便稍後啟動、停止輸入處理。通常在應用程式第一次啟用輸入法時調用此方法。

  參數

  binding    與輸入法綁定的應用程式視窗資訊。

  參見

  public abstract void createSession (InputMethod.SessionCallback callback)

  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)需要輸入的屬性

  public abstract void revokeSession (InputMethodSession session)

  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 位。

  public abstract void startInput (InputConnection inputConnection, EditorInfo info)

  應用程式開始接收文本,輸入法準備好為應用程式處理接收事件并傳回文本時調用本方法。

  info  需要輸入的文本框(通常是EditText)資訊。

  public abstract void unbindInput ()

通常在應用程式變為非前台調用。

本文轉自over140 51CTO部落格,原文連結:http://blog.51cto.com/over140/582435,如需轉載請自行聯系原作者

繼續閱讀