问题
My Android app contains a custom slider control based on the SeekBar
, and I want to attach a custom text phrase to my control to explain its use for Accessibility.
I have done this successfully using View.setContentDescription(text)
, and TalkBack correctly speaks the phrase when I request focus on my slider control from Activity.onCreate
.
So far, so good. However, when I touch the control, which I believe sets the AccessibilityFocus on my Android API 16 test device, extra words are being added to the spoken phrase, i.e. '...seek control. 0 per cent'. I want to remove these additional words.
I have tried to eliminate them using event.getText().clear()
in View.onInitializeAccessibilityEvent(event)
without success. Echoing the event to LogCat reports the correct phrase in event.contentDescription
and no entries in event.text
, but the extra words appear both in the audio output from the device hardware and in the on-screen debug text displayed by Menu->Settings->Accessibility->TalkBack->Settings->Developer Settings->Display Speech Output.
Please can anyone suggest where the extra words are being added, and how to eliminate them?
Any constructive suggestions would be welcomed. Thanks.
Update
I can see that some Explore By Touch (initial single-tap) event on my custom control does not pass through either its onInitializeAccessibilityEvent
or dispatchPopulateAccessibilityEvent
methods as I am deliberately calling event.setContentDescription(null)
. Despite this, there is an AccessibilityEvent
being generated with my custom control's ContentDescription
, set in Activity.onCreate
in code, plus the extra words I'm trying to eliminate.
I've also set an AccessibilityDelegate
on my custom control's parent ViewGroup
to give visibility of its onRequestSendAccessibilityEvent
calls. This confirms that no event containing my ContentDescription
is passing through.
This is very puzzling, and happens on both the emulator and real hardware with API 16. Any ideas?
回答1:
You also need to override http://developer.android.com/reference/android/view/View.html#onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)
and set the contentDescription there.
If you want to remove the 0%, I would try to change the class in AccessibilityNodeInfo/AccessibilityEvent: http://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo.html#setClassName(java.lang.CharSequence)
回答2:
I believe that this is a bug in TalkBack, and have raised Google Eyes-Free issue #375, including example code.
Update: Google have now archived this. Link moved to: http://code.google.com/archive/p/eyes-free/issues/375
来源:https://stackoverflow.com/questions/25001069/android-how-to-eliminate-spoken-text-from-accessibilityevents-when-extending-se