Send accessibility event not linked to view

后端 未结 3 1644
臣服心动
臣服心动 2021-01-05 22:45

We\'re looking to send an accessibility event (which would be picked up by TalkBack etc.) which isn\'t linked to a view.

For example, how could I send an accessibili

3条回答
  •  误落风尘
    2021-01-05 23:04

    You can use the accessibility manager directly (since API 14) like @alanv said. But since API 16, you must provide a view.

    final View parentView = view.getParent();
    if (parentView != null) {
        final AccessibilityManager a11yManager =
                (AccessibilityManager) view.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    
        if (a11yManager != null && a11yManager.isEnabled()) {
            final AccessibilityEvent e = AccessibilityEvent.obtain();
            view.onInitializeAccessibilityEvent(e);
            e.getText().add("some text");
            parentView.requestSendAccessibilityEvent(view, e);
        }
    }
    

提交回复
热议问题