【问题标题】:Access all View attributes from InputMethodService从 InputMethodService 访问所有视图属性
【发布时间】:2020-09-05 23:19:47
【问题描述】:

我正在尝试从启动我的键盘的View 访问一些属性。例如,如果我的应用中有以下视图:

<EditText
  android:contentDescription="content description"
  android:privateImeOptions="private ime options" />

我可以像这样从InputMethodService 访问privateImeOptions

@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
    final String privateImeOptions = info.privateImeOptions;
}

但是我不能以同样的方式访问contentDescription 属性。

有没有一种方法可以读取特定属性,例如启动 IME 的 ViewcontentDescription?我只需要对该属性的读取权限,不需要更改它。

【问题讨论】:

    标签: android ime


    【解决方案1】:

    对此的简短回答是否定的,无法从InputMethodService 访问属性

    但是,有一个解决方案使用AccessibilityService 读取View 属性,然后将此信息传递给InputMethodService

    无法确认键盘和辅助功能服务视图是否匹配,但您可以假设焦点所在的视图是启动键盘的视图。要从无障碍服务中获得焦点视图,您可以使用

    final AccessibilityNodeInfo focusedView = findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
    

    对于大多数情况来说,这可能不是一个理想的解决方案,但我想将它记录下来,以供将来可能会发现它有用的任何人使用

    【讨论】:

      猜你喜欢
      • 2019-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多