Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting content description for option menu android Talkback

I am implementing "Read Aloud" or "Talkback" for an app. Everything is working with contentDescription text, but with option menu, I found nothing related to contentDescription, I want system read "Menu "+ item's name.

EX: My menu has 2 items: "Create New Folder" and "Delete current folder", currently, when I focus a menu item (Support trackball and bluetooth key), system can talk exactly the menu's text. But I want it talks more like "1: Menu Create New Folder" and "2: Menu Delete current folder".

So, How can I change the read text? How can I get the focused menu item when bluetooth keyboard press UP/DOWN key?

like image 667
NamNH Avatar asked Apr 22 '16 15:04

NamNH


People also ask

What is content description in Android?

The content description attribute links a text description to a control, ImageView, or other focusable object that otherwise has no text content. These objects wouldn't be accessible without some some sort of label or description.

How do I change my TalkBack settings?

Change the volume for TalkBack It's part of Android's standard volume control. To change the speaking volume: While Talkback speaks, press the volume up or volume down key. If TalkBack isn't speaking, hold one finger on the screen and press the volume up or volume down key.

What is TalkBack menu?

The TalkBack menu: contains commands that are relevant anywhere on your device. To open the TalkBack menu, swipe down then right, or swipe up then right. Or on devices with multi-finger gestures*, you can also do a three-finger tap.


4 Answers

this answer post AndroidX

androidx.core.view.MenuItemCompat.setContentDescription(menuItem,  contentDescription)
like image 31
Amit Avatar answered Oct 17 '22 06:10

Amit


It seems they just added the setContentDescription(CharSequence contentDescription) method to the MenuItem class on API 26 (Android O)

like image 38
dasfima Avatar answered Oct 17 '22 07:10

dasfima


MenuItemCompat in the v4 support libraries has a

android.support.v4.view.MenuItemCompat.setContentDescription(MenuItem menuItem, CharSequence contentDescription) 

method for backwards compatibility on pre-Oreo devices.

For AndroidX see this answer:

https://stackoverflow.com/a/57950952/1236327

like image 167
tim.paetz Avatar answered Oct 17 '22 08:10

tim.paetz


As my investigation, in Android internal source code, class ActionMenuItemView.java method setTitle(CharSequence title), the source code also sets setContentDescription(title), so Android will read your MenuItem's text as default. I don't know why the core has so inflexible in this case.

Updated:

Thanks for @sofakingforever answer.

Seem Google just added the setContentDescription(CharSequence contentDescription) method to the MenuItem class on API 26 (Android O).

Updated: Thanks for new @tim.paetz answer . Look like all versions are now supported setContentDescription for menu item using android support v4 libraries.

like image 22
NamNH Avatar answered Oct 17 '22 08:10

NamNH