给定以下代码:

InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> inputMethods = imm.getEnabledInputMethodList();
for(InputMethodInfo method : inputMethods){
    String name = method.loadLabel(activity.getPackageManager()).toString();
    new InfoDialog(activity,name).show();
    //imm.setInputMethod(token, id);
}


我的设备中安装了两种输入法:Samsung Keyboard和Google手写输入。我试图做的是使用setInputMethod在这两个键盘之间切换。

例:

imm.setInputMethod(<Samsung Keyboard>);


要么

imm.setInputMethod(<Google Handwriting Input>);


怎么做?任何想法?

最佳答案

嗯,没有办法被动地更改它,而是提示用户这样做

InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();


但是,如果您具有系统特权,则可以像这样更改它:

Settings.Secure.putString(resolver, Settings.Secure.ENABLED_INPUT_METHODS, "com.package.to.keyboard/.full.path");
Settings.Secure.putString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD, "com.package.to.keyboard/.full.path");

关于android - 如何在InputMethodManager类中使用setInputMethod,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37958223/

10-09 05:18