【问题标题】:How can I change TalkBack speech when a list item gets focus?当列表项获得焦点时,如何更改 TalkBack 语音?
【发布时间】:2012-09-18 14:21:10
【问题描述】:

我使用 Google UserRowView 类作为模板,说明如何覆盖 dispatchAccessibilityEvent() 以便让 TalkBack 说出自定义消息:

public class UserRowView extends LinearLayout {
                .
                .
  public void setText(String text) 
      _message = text;
  }

  @Override
  public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent accessEvent) {
      Context ctx = this.getContext();
      accessEvent.setClassName(getClass().getName());
      accessEvent.setPackageName(ctx.getPackageName());
      accessEvent.getText().clear();
      accessEvent.getText().add(_message);
      return true;
  }

列表项布局为:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="@color/all_white">
<ImageView
    android:id="@+id/catalog_entry_image"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:src="@drawable/member_active" />
<com.topiatechnology.skoot.android.util.UserRowView
    android:id="@+id/catalog_entry_user_row_view"
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    >
    <TextView
        android:id="@+id/catalog_entry_name_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />
    <TextView
        android:id="@+id/catalog_entry_size_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
    />
    <TextView
        android:id="@+id/catalog_entry_date_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal" 
        android:layout_width="200dip" 
        android:layout_height="wrap_content"
        android:id="@+id/catalog_entry_progress_bar"
        android:visibility="gone"
    />
</com.topiatechnology.skoot.android.util.UserRowView>
</LinearLayout>

我在 ListView 的适配器中的 getView() 方法中设置了文本。

问题在于,当关注列表项时,TalkBack 不会更改它所说的文本。

对于上面的布局,三个 TextView 的文本被朗读,而我希望我设置的文本被朗读。我怎样才能做到这一点?

【问题讨论】:

    标签: android accessibility


    【解决方案1】:

    使用View.setContentDescription() 在包含您不想大声朗读的视图的布局上设置内容描述。 TalkBack 将读取内容描述并忽略子视图的文本。

    . . .
    
    public void setText(String text) 
        _message = text;
        setContentDescription(_message);
    }
    

    一般情况下,不再建议将 AccessibilityEvent 文本设置为控制来自焦点和选择的反馈。

    【讨论】:

    • 在尝试覆盖 dispatchPopulateAccessibilityEvent 之前我一直在设置内容描述,但忘记使视图无效。我根据您的建议删除了覆盖。一旦我在调用 setContentDescription 后使视图无效,就会大声朗读描述。需要注意的是,我注意到布局中视图的内容描述仍在使用中。
    • 您能检查一下您正在运行的 TalkBack 版本吗?设置 > 应用程序 > 全部 > TalkBack
    • 我正在运行版本 3.1.1_r68。
    • 从代码示例中,看起来一切都设置正确。这可能会在当前的 beta 版本中得到修复,该版本位于 eyes-free.googlecode.com/files/… 如果这仍然是一个问题,请告诉我,我们可以在下一个 Play Store 版本之前修复它。
    • 当我在包含一些 TextView 的 LinearLayout 上设置内容描述时,会大声朗读 LinearLayout 的内容描述和每个 Textview 的文本。我不确定这是否是预期的行为。
    猜你喜欢
    • 1970-01-01
    • 2016-09-18
    • 2014-05-29
    • 1970-01-01
    • 2018-02-10
    • 2012-08-24
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多