How to change Android Talkback instructions for double tap and long press

I have a view that has a long click action handler. I use the content description to set the Talkback message when the focus is focused.

He is currently talking about my description of the content immediately after receiving the focus, and after a short pause he says:

Double tap to activate, double press and hold

I want to change this message to something like

Double tap on "action 1" , double tap and hold for "action 2"

Is there any way to do this?

I looked at onPopulateAccessibilityEvent() , it received the TYPE_VIEW_ACCESSIBILITY_FOCUSED event, but I could not change the desired message.

Am I missing something simple?

+5
source share
3 answers

In API 21+, you can customize action names by setting custom actions to View AccessibilityNodeInfo . There are two approaches to this: 1) set the AccessibilityDelegate and override the delegate method onInitializeAccessibilityNodeInfo or 2) extend the view class and override the onInitializeAccessibilityNodeInfo .

In any case, you will create a new AccessibilityAction and set it to node using AccessibilityNodeInfo.addAction .

If you decide to use a delegate, you must configure a custom description for the click action as follows:

 view.setAccessibilityDelegate(new AccessibilityDelegate() { @Override public void onInitializeAccessibilityNodeInfo( View v, AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfo(v, info); // A custom action description. For example, you could use "pause" // to have TalkBack speak "double-tap to pause." CharSequence description = getResources().getText(R.string.my_click_desc); AccessibilityAction customClick = new AccessibilityAction( AccessibilityAction.ACTION_ACTION_CLICK, description); info.addAction(customClick); } }); 

If you are using API applications <21, replace the corresponding *Compat Support Library methods. This function is not supported in the reverse order, so you won’t get user-defined descriptions in API <21, but you can avoid explicit version checks in the application code.

+3
source

AccessibilityAction seems to have changed a bit since alanv posted its answer. The following is a working solution using ViewCompat :

 ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat() { @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); // A custom action description. For example, you could use "pause" // to have TalkBack speak "double-tap to pause." CharSequence description = host.getResources().getText(R.string.my_click_desc); AccessibilityActionCompat customClick = new AccessibilityActionCompat( AccessibilityNodeInfoCompat.ACTION_CLICK, description); info.addAction(customClick); } }); 
+1
source

Use the code below for anyone who wants to delete the entire phrase ie. "double click on".

 ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat() { @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); info.addAction(AccessibilityNodeInfoCompat.ACTION_FOCUS); } }); 

This basically calls the code below, and requestFocus has no default messages associated with it.

 case AccessibilityNodeInfo.ACTION_FOCUS: { if (!hasFocus()) { // Get out of touch mode since accessibility // wants to move focus around. getViewRootImpl().ensureTouchMode(false); return requestFocus(); } } 
0
source

All Articles