2

我有一个从 "MultiAutoCompleteTextView" 扩展的自定义视图。当用户开始在 CustomTextView 中输入时,弹出窗口将显示建议值。在选择这些值之一时,CustomTextView 将填充所选值。

可以选择的值有 ID 和名称。默认情况下,当用户从列表中选择一个值并且 CustomTextView 填充了该选定值时,TalkBack 会以一种奇怪的方式读出选定项的 ID。

它读到

"(itemID as a whole word) 替换 syn (itemId as individual charachers) comma space"

例如,如果 id 是 apple 它读取

“apple 替换了 syn apple 逗号空间”

我希望它只读出名称而不是 ID。

阅读可访问性文档以添加可访问性的自定义视图(http://developer.android.com/guide/topics/ui/accessibility/apps.html#custom-views)我尝试覆盖不同的 API 并设置事件文本,但是一旦我对事件文本做任何事情,就什么都不会被读出。

我只需要支持 API 15 及更高版本,所以在我的 CustomTextView 中我添加了代码

public void onPopulateAccessibilityEvent(AccessibilityEvent event){
    super.onPopulateAccessibilityEvent(event);
    System.out.println("onPopulateAccessibilityEvent \n s = " + s 
                        + "\n event text = " + event.getText());

    CharSequence c = "Test";
    event.getText().clear();
    event.getText().add(c);

    System.out.println("event text after setting = " + event.getText());
}

我可以在我的调试系统输出中看到事件文本正在从 id 更新为“测试”

onPopulateAccessibilityEvent
s = Jo Blogs
event text = [UID1234, ]
event text after setting = [Test]

因此我不明白为什么没有大声读出字符串“Test”?有任何想法吗?

注意:如果我添加以下代码,则当触摸 CustomTextView 时,会正确读出“Touched on CustomTextView”。但是,覆盖此方法对于首次从建议中选择项目并填充 CustomTextView 没有任何影响。

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info){
    super.onInitializeAccessibilityNodeInfo(info);
    info.setText("Touched on CustomTextView");
}
4

1 回答 1

0
With the following accessibility methods overwritten this now seems to be working

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info){
    super.onInitializeAccessibilityNodeInfo(info);

    String s = getAccessibilityUsernameString();

    if (s != null && null != getAccessibilityUserNames()) {
        info.setText(s);
    }
}


@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    super.onPopulateAccessibilityEvent(event);

    String s = getAccessibilityUsernameString();

    if (s != null) {
        event.getText().clear();
        event.getText().add(s);
    }
}   

where "getAccessibilityUserNames()" gets a string containing the names of the objects selected and "getAccessibilityUsernameString" returns a string "Selected items are %1$s"
于 2016-08-25T16:29:45.113 回答