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?
If you dig through the TalkBack project, in Role.java, you will see that the hint text "button" is applied in the following circumstances:
OR
android.widget.ImageView
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.