【问题标题】:How to get ID of user set default keyboard in Android如何在Android中获取用户设置默认键盘的ID
【发布时间】:2016-04-20 02:21:02
【问题描述】:

我想在我的自定义键盘中创建一个按钮,按下该按钮会将键盘切换到默认用户键盘。我已经想出了如何像这样设置输入键盘:

final String LATIN = "com.android.inputmethod.latin/.LatinIME";
final IBinder token = this.getWindow().getWindow().getAttributes().token;
imm.setInputMethod(token, LATIN);

在这种情况下,按下我想要实现的按钮会将键盘切换到用户指定的默认键盘(拉丁键盘)。

问题在于这个特定示例中的字符串已经给出。

如何找到默认用户指定键盘的 ID 字符串,以便设置InputMethod。

【问题讨论】:

    标签: android android-softkeyboard


    【解决方案1】:

    您可以像以下示例一样获取当前活动键盘的 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(); }
    

    【讨论】:

      猜你喜欢
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 2013-02-10
      • 2016-02-03
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多