本文介绍了安卓:确定从code动态输入法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何确定哪种输入法是当前活动 - 用户可以切换输入法(软键盘)由长pressing上的文本编辑字段 - 从code,一个人如何确定哪种输入法用户选择

How do you determine which input method is currently active - A user can change the input method (soft keyboard) by long pressing on a text edit field - From code, how does one determine which input method the user has chosen

推荐答案

我知道你可能不需要这个了,但有人可能会想这个问题的答案。您可以使用此行来获得输入法的使用串ID:

I realise you probably don't need this anymore, but someone might want the answer to this. You can use this line to get the String ID of the Input Method in use:

String id = Settings.Secure.getString(
   getContentResolver(),
   Settings.Secure.DEFAULT_INPUT_METHOD
);

如果你想获得关于当前键盘的更多信息,你可以使用:

If you want to get more information about the current keyboard, you can use:

    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);

        if (imi.getId().equals(Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {

            //imi contains the information about the keyboard you are using
            break;
        }
    }

这篇关于安卓:确定从code动态输入法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:58