当前位置: 代码迷 >> Android >> 100分!关于setInputMethod()切换输入法有关问题,得不到token。求切换输入法方法
  详细解决方案

100分!关于setInputMethod()切换输入法有关问题,得不到token。求切换输入法方法

热度:57   发布时间:2016-04-28 07:15:15.0
100分!关于setInputMethod()切换输入法问题,得不到token。求切换输入法方法
本帖最后由 baodinglaolang 于 2011-12-01 19:22:59 编辑
最近有需求需要进行切换输入法,
知道有两种方法,一种InputMethodManager.setInputMethod(IBinder token, String id)
一种是 InputMethodService.switchInputMethod(String id)

经过测是第一种,第一个参数怎么也搞不定,我现在只能得到这个程序的一个View  我试着用 
view.getWindowToken()
 view.getApplicationWindowToken() 两种方法传进去,都无法改变。


而用 InputMethodService.switchInputMethod(String id)  这个,我根本不知到怎么得到InputMethodService的实例,
试着new了一个,结果报空指针~~~

各位大牛帮忙,看看怎么才能切换输入法,前提是我现在只获得了一个这个程序的 view ,因为我是在framework的inputmethodmanager.java里修改,当前修改的是focusin()方法,focusin()中只传来了程序的一个view,另外 setInputMethod(IBinder token, String id) 也是这个类本身的方法。

------解决方案--------------------
这个可以通过将输入法的ID写入系统设置中来完成,大概代码是这样的:
Settings.Secure.putString(contentResovler,Settings.Secure.DEFAULT_INPUT_METHOD,"输入法的ID");
InputManagerService会监听这个设置项的改变。
------解决方案--------------------
这个好像涉及到AIDL,具体要问问google
------解决方案--------------------
可以试试activeActivity.getCurrentFocus().getToken()
------解决方案--------------------
引用:
已经解决了额  改framework
大家有其他更好的方法也可以说说啊


可以大致分享下吗 
  相关解决方案