Android-将“话语提示”可访问性焦点设置为特定视图 [英] Android - Set TalkBack accessibility focus to a specific view

查看:125
本文介绍了Android-将“话语提示”可访问性焦点设置为特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启用话语提示后,有什么方法可以将可访问性焦点手册设置为特定视图?例如,当我的活动开始时,我希望话语提示自动关注某个按钮(视图周围的黄色框)并阅读其内容说明。

When TalkBack is enabled, is there any way to set the accessibility focus manual to a specific view? For instance, when my Activity is started I want TalkBack to automatically focus on a certain Button (yellow frame around the view) and read its content description.

我所拥有的到目前为止已经尝试过:

What I've tried so far:

    myButton.setFocusable(true);
    myButton.setFocusableInTouchMode(true);
    myButton.requestFocus();

requestFocus()似乎仅请求输入焦点,而与可访问性焦点无关。我也尝试过:

requestFocus(), it seems, is only requesting input focus and has nothing to do with accessibility focus. I've also tried:

    myButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
    myButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    myButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
    myButton.announceForAccessibility("accessibility test");
    myButton.performAccessibilityAction(64, null); // Equivalent to ACTION_ACCESSIBILITY_FOCUS

    AccessibilityManager manager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (manager.isEnabled()) {
        AccessibilityEvent e = AccessibilityEvent.obtain();
        e.setSource(myButton);
        e.setEventType(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
        e.setClassName(getClass().getName());
        e.setPackageName(getPackageName());
        e.getText().add("another accessibility test");
        manager.sendAccessibilityEvent(e);
    }

这些似乎都不起作用。

推荐答案

免责声明:始终将活动负载的重点放在任何位置,但始终放在顶部栏(好吧,永远不应该总是说),但实际上,只是不要做吧。这分别违反了有关可预测的导航和上下文更改的各种WCAG 2.0法规,包括3.2.1和3.2.3。通过执行此操作,您实际上可能会使您的应用更不可访问。

DISCLAIMER: Forcing focus on Activity load to be anywhere but at the top bar is always (okay, always should almost never be said), but really, just don't do it. It is a violation of all sorts of WCAG 2.0 regulations, including 3.2.1 and 3.2.3, regarding predictable navigation and context changes respectively. You are, likely, actually making your app MORE inaccessible by doing this.

http://www.w3.org/TR/WCAG20/#consistent-behavior

END免责声明。

您正在使用正确的函数调用。您所需要做的就是:

You are using the correct function calls. All you should need to do is this:

myButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

问题很可能是您尝试执行此操作的时候。对讲会在活动周期的稍后阶段将其自身附加到您的活动上。老实说,以下解决方案说明了此问题,我不确定有更好的方法来解决此问题。我尝试了onPostResume,这是Android OS调用的关于活动加载的最后一个回调,但仍然不得不延迟。

The problem is more likely the point at which your attempting to do this. Talkback attaches itself to your activity slightly later in the activity cycle. The following solution illustrates this problem, I'm not sure there is a better way to do this, to be honest. I tried onPostResume, which is the last callback the Android OS calls, regarding the loading of activities, and still I had to add in a delay.

@Override
protected void onPostResume() {
    super.onPostResume();

    Log.wtf(this.getClass().getSimpleName(), "onPostResume");

    Runnable task = new Runnable() {

        @Override
        public void run() {
            Button theButton = (Button)WelcomeScreen.this.findViewById(R.id.idButton);
            theButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
        }
    };

    final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();

    worker.schedule(task, 5, TimeUnit.SECONDS);

}

您也许可以创建自定义视图。视图中的回调可能会提供您所需的逻辑,而不会出现争用条件!如果有时间,我可能会在以后再研究。

You might be able to create a custom view. The callbacks within view, may provide the logic you need to do this, without the race condition! I might look into it more later if I get time.

这篇关于Android-将“话语提示”可访问性焦点设置为特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆