最近有需求需要进行切换输入法,
知道有两种方法,一种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()
------解决方案--------------------
可以大致分享下吗