2012-02-25 34 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

相关问题