【问题标题】:Android How to get talkBack to read text when RelativeLayout is displayedAndroid如何在显示RelativeLayout时让talkBack读取文本
【发布时间】:2014-08-12 14:36:28
【问题描述】:

我有一个活动,它使用以下代码向整个活动的视图添加自定义视图

activity.getWindow().getDecorView()).addView(newView)

为了显示教练标记/用户提示屏幕。

我的自定义视图从 RelativeLayout 扩展而来,并在其构造函数中在屏幕底部添加了一个按钮,单击该按钮会关闭视图。

我已经覆盖了“dispatchDraw”方法,这样我就可以将多个coachmark UI 对象(文本视图和位图)添加到特定位置的布局中。这些 coachmark 对象使用如下代码在视图上绘制自己

        canvas.save();
        canvas.translate(positioning[0], positioning[1]);
        textView.draw(canvas);
        canvas.restore();

        canvas.save();
        canvas.drawBitmap(bitmap, positioning[2], positioning[3], new Paint());
        canvas.restore();

问题:启用 TalkBack 时

  • 当显示此教练标记视图时,不会大声读出任何内容 此视图
  • 如果用户按下文本视图和位图所在的位置,则没有任何内容 大声朗读

但是,当用户按下按钮时,按钮的 contentDescription 会被大声读出。

我认为 textViews 和 Bitmaps 没有被读出的原因是由于我上面的代码在画布上呈现它们的方式。

问题 1: 有没有办法让 TalkBack 在单击文本视图和位图时大声说出某些内容? - 我已经尝试为 textviews 和 bitmaps 设置 contentDescriptions 和可聚焦,但这没有任何区别。

问题 2: 另一种方法是让 TalkBack 在显示自定义视图时读出一些内容,并且此文本可以总结屏幕上显示的所有辅助标记。我不知道该怎么做,有人有什么建议吗? - 我尝试将我的 customView 设置为可聚焦(setFocasable(true) 并给它一个 contentDescription 但这不起作用。 - 我尝试在绘制自定义视图时发起一个操作,然后向事件添加内容描述,但这也不起作用,即

protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
}

@Override
public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    // this is not read out load when the view is displayed, but is read when the view is pressed
    info.setContentDescription("on Initialize Accessibility Node Info User Tips");
}

【问题讨论】:

    标签: android bitmap android-relativelayout custom-view talkback


    【解决方案1】:

    我最近一直在努力解决类似的问题。

    简短的回答是在您希望触发 TalkBack 时使用 View.announceForAccessibility(text),假设您使用的是 Android API 16 或更高版本 - 请参阅 Android docs

    但是,如果您想支持早期的 Android API,可以使用View.requestFocus() 提供更复杂的答案,我已在此处概述:Android: How to force Explore-By-Touch/Talkback to repeat the ContentDescription of the current View in AccessibilityFocus?

    我还建议您查看我针对 Google 的 Eyes-Free 代码提出的几个错误,这可能会为您节省一些浪费的精力:

    【讨论】:

    • @Sarah Maslin 你的问题解决了吗?我很想知道结果。
    猜你喜欢
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 2015-03-19
    • 2014-09-22
    相关资源
    最近更新 更多