0

I have gone through many questions, API demo regarding Accessibility feature in Android but it couldn't help.

I want to support Accessibility in my Android application. Inbuilt Accessibility is taking care of all the focusable items and reads out the Hints correctly when clicked.

I want to fire Accessibility events whenever user clicks on TextView.And the first time the screen is opened, I want it to read out custom information which I provide. I have managed to do it with dispatchPopulateAccessibilityEvent but it reads everytime when screen is resumed. Also I can not identify which view is sending the event.

rds
  • 26,253
  • 19
  • 107
  • 134
Harshad
  • 7,904
  • 3
  • 24
  • 42

3 Answers3

2

You can use the call "sendAccessibilityEvent", from within your TextView, like this:

if (AccessibilityManager.getInstance(mContext).isEnabled()) {
    setContentDescription("The content description for this view");
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}

The text read off (depending on which Accessibility Service is being used) will be based off the content description, not necessarily the text in the TextView.

Alexander Lucas
  • 22,171
  • 3
  • 46
  • 43
1

If you want your view to be focused and annouce associated content description for that view then, You can use,

view.requestFocus()
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)

If you just want to announce the change once only and don't want to change contentDescription associated with that view, you can use

view.announceForAccessibility = "Alert to a user about some event."

Note: announceForAccessibility will not get accessibility focus on your view.

Dhara Vamja
  • 554
  • 4
  • 17
0

You can use the

view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

On your TextView, also you can add the "announceForAccessibility" but you should validation if the version is greater or equals than Jelly Bean but for that you need a change on the view.

Finally if you want to announce the "title" of the page, for example, the activity you could add the setTitle for the activity and put your text, remember use a Toolbar with a title because this setTitle by default will override the action bar title.

Let me know if you have any other issue.

StarsSky
  • 6,721
  • 6
  • 38
  • 63