When using TalkBack, what is the preferred way to alert the user when the contents of a TextView have changed?

我是研究僧i 提交于 2019-11-28 21:53:30

You should be able to use View.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) on your TextView to trigger TalkBack in the same way that View.requestFocus() would. Since it only triggers the event, and doesn't actually focus the View, it shouldn't crash after the first time.

salfon

I was using the accepted answer, which works well. However, I didn't like the misleading sound when accessibility focus was set on the text view - the same sound as when input focus is given to an EditField by double-tapping (a sort of drawer-open sound), because the input focus had not actually moved from the EditText with inputfocus (eg with cursor).

So I tried:

m_textView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);`

and interestingly it works - the label is read, without moving any focus or giving any other sound.

OK, if you are using L or later the better answer is to use: http://developer.android.com/reference/android/view/View.html#setAccessibilityLiveRegion(int)

This will do all the work for you.

Another way would be to, when TalkBack is activated, additionally show a Toast message with the error text. This is also being read out aloud.

vijesh

Recommended way is to use the below code after textview change.

textview.sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);

It will read the contents without focusing on it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!