我有一个自定义视图,它扩展自" MultiAutoCompleteTextView" 。当用户开始在CustomTextView中键入时,弹出窗口将显示建议值。在选择其中一个值时,将使用所选值填充CustomTextView。
可以选择的值具有ID和名称。默认情况下,当用户从列表中选择一个值并使用所选值填充CustomTextView时,TalkBack会以奇怪的方式读出所选项的ID。
它读取
"(itemID作为整个单词)替换syn(itemId作为单个charachers)逗号空间"
例如,如果id为apple,则为
" 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]
因此我不明白为什么字符串"测试"没有大声朗读?有什么想法吗?
注意:如果我添加以下代码,那么当触摸CustomTextView然后"触摸CustomTextView"被正确读出。但是,如果首先从建议中选择了一个项目并且填充了CustomTextView,则覆盖此方法没有任何区别。
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info){
super.onInitializeAccessibilityNodeInfo(info);
info.setText("Touched on CustomTextView");
}
答案 0 :(得分: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"