【问题标题】:How to know if an `InputMethod` is enabled?如何知道是否启用了“InputMethod”?
【发布时间】:2016-10-20 23:37:02
【问题描述】:

我正在从头开始编写自定义InputMethod,并希望在我的Activity 中向用户显示一个按钮,以启用我的InputMethod,以防它被禁用...

我需要以编程方式确定我的InputMethod 是否在设备中启用。

我该怎么做?

【问题讨论】:

    标签: android android-input-method


    【解决方案1】:

    您可以使用InputMethodManager 获取启用的InputMethodInfo 列表并对其进行迭代以了解您的InputMethod 是否已启用。

    public boolean isMyInputMethodEnabled() {
        boolean isEnabled = false;
    
        InputMethodManager inputMethodManager
                = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        List<InputMethodInfo> inputMethodList = inputMethodManager
                .getEnabledInputMethodList();
    
        for (InputMethodInfo inputMethodInfo : inputMethodList) {
            if (inputMethodInfo.getPackageName().equals(getPackageName())) {
                isEnabled = true;
                break;
            }
        }
    
        return isEnabled;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多