2012-02-25 67 views
3

我想做一些簡單的事情,但是,因爲它帶來了困難的任務。 我有EditText控件。我想要做的是當我停止輸入它時(onFocusChanged,focus = false)我想記錄鍵盤的狀態 - 哪種語言正在使用,下次如果我看到鍵盤被'記住'我想要像以前一樣設置它。Android:如何確定正在使用哪個鍵盤

我試圖查看IMF和IME,但這些只給了我一些信息,但沒有「設置」選項,所以這不是我所需要的。 另一方面有KeyboardView - 有一些功能可以幫助(getKeyboard,setKeyboard),但我不知道如何獲得KeyboardView!

爲什麼我需要這個?我有2個EditText,每個語言都會有所不同,所以用戶必須自己改變語言,這是非常令人煩惱的,因爲輸入迭代次數很高。如果我只記得用過的鍵盤...... :)

感謝您的幫助!

回答

2
public InputMethodInfo getCurrentImeInfo(){ 
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
    List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList(); 

    final int n = mInputMethodProperties.size(); 
    for (int i = 0; i < n; i++) { 

     InputMethodInfo imeInfo = mInputMethodProperties.get(i); 

     if (imeInfo.getId().equals(Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { 

      return imeInfo; 
     } 
    } 
    return null; 
} 
+0

這不會幫我下一次設置正確的鍵盤.. 我真的不明白這是什麼有DEFAULT_INPUT_METHOD做.. – 2012-02-25 12:18:36

+0

'InputMethodInfo'有ID,它可以用來在InputMethodManager.setInputMethod' – 2012-02-25 12:21:02

+0

這個ID給我我使用的鍵盤的名稱,但不是我在這個鍵盤上選擇的語言:) – 2012-02-25 13:01:58