作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想在我的自定义键盘中创建一个按钮,按下该按钮会将键盘切换为默认用户键盘。我已经想出如何像这样设置输入键盘:
final String LATIN = "com.android.inputmethod.latin/.LatinIME";
final IBinder token = this.getWindow().getWindow().getAttributes().token;
imm.setInputMethod(token, LATIN);
在这种情况下,按下我想要实现的按钮会将键盘切换到默认的用户指定键盘(拉丁键盘)。
问题是在这个特定的例子中,字符串已经给出了。
如何找到默认用户指定键盘的 ID 字符串,以便我可以设置 InputMethod
。
最佳答案
您可以像下面的例子一样获取当前 Activity 键盘的 id:
String id = Settings.Secure.getString(
getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD)
如果您的软键盘当前正在用于输入,以上代码将返回您的键盘的 id。
但是,你可以这样做:当您的输入选择器按钮被点击时,您可以显示输入法列表,并让用户选择他喜欢的任何输入法:
InputMethodManager inputManager = (InputMethodManager) this.getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showInputMethodPicker();
以上代码将打开一个系统对话框,您可以在其中选择输入法。此外,您还可以获得输入法列表,如下面的代码所示:
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 imi = mInputMethodProperties.get(i);
Log.d("TAG", "Input Method ID: "+ getApplicationContext().getPackageName(); }
关于android - 如何在Android中获取用户设置默认键盘的ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36732684/
我是一名优秀的程序员,十分优秀!