Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell TalkBack a custom view is being used as a button

I’m using a custom view as a button on Android, which doesn't inherit from android.widget.Button. What is the best way of telling the accessibility services it's a button?

Is it enough to just call setClickable(true) on the view?

With a standard Button, TalkBack appends the word "button" as a hint, but with a custom view it doesn’t do that. Should I be adding the word "button" as a hint somewhere?

On iOS, I’d add a button "trait" to the view, and VoiceOver annonces it as a button. Is there anything similar on Android?

like image 654
Tom Gilder Avatar asked Dec 08 '17 15:12

Tom Gilder


1 Answers

If you dig through the TalkBack project, in Role.java, you will see that the hint text "button" is applied in the following circumstances:

  • The element has a class of android.widget.Button

OR

  1. The element has a class of android.widget.ImageView
  2. The element isClickable()

HOWEVER, anything that isClickable() will have the hint text "Double tap to ...." applied to it. So, the answer is NO, you should not. "Button" means something very specific to TalkBack users, and it is best to allow the Android Operating System and TalkBack to work together to figure out what that is.

Would it be better if TalkBack just announced all Trivially clickable things as buttons, instead of putting that information in the delayed hint text: "Double tap to..." (... = Expand, activate, etc, depending on control) Yes, it probably would.

Would it be better if Android allowed you to say: "Yes this thing I've subclassed is a button", like iOS traits. Yes, it probably would.

In fact, I would argue that given the: "Double tap to ...." announcement, that the announcement of "button" in this scenario is additional information. "Button" means nothing more than the thing can be double tapped to be actioned. If "button" announcement only applied to "buttons" this wouldn't be the case, as "android.widget.Button" objects are styled certain ways (typically). But, since this is also applied to IMAGE_VIEWS, without being applied to other simple "clickable" views, its purpose is muddy, and ultimately useless and confusing. AND NO, you should not attempt to rectify this. It is absolutely TalkBack's job to get this right, which it does... just in other ways. Let me explain:

The announcement of button has essentially been deprecated, and replaced by the delayed announcement "double tap to ...". The "button" announcement was left in as legacy support for users that were accustomed to that announcement.

To summarize: ensure that "Double tap to ...." is announced AFTER your control. Though, just ensuring that your node has a click listener and "isClickable" should be enough for this. This delayed hint announcement is the important bit. The announcement of "button" is unimportant, legacy garbage leftover from unfortunate decisions made early on in the development of the TalkBack project. THAT, or it will be fixed to be applied to all clickable things (like custom controls) in a future release. Either way, adding the word "button" to your content description would be ill advised.

like image 124
ChrisCM Avatar answered Sep 19 '22 17:09

ChrisCM