Currently, when the SeekBar is selected it says "%d percent, <content description>, Seek Control" and then "Use volume keys to adjust...", which is the default TalkBack for this SeekBar, but in my case, this is useless information, since the SeekBar moves in steps, for example, it can slide to option A, or option B or option C.
What I want is when the SeekBar is selected, TalkBar should read the content description only, or even better, just remove the "%d percent".
I'm trying to modify the default TalkBack in a custom SeekBar Inheriting from androidx.appcompat.widget.AppCompatSeekBar but nothing that I've tried worked.
I've tried:
reading the accessibility documentation for custom views but changing the event text did nothing: Make custom views more accessible.
I tried to change the event.text.add("custom text") in all possible API methods. Also tried to use event.clear() before adding new text and to change the event.beforeText. Nothing worked
this solution, but when I select the SeekBar it reads nothing. I'm guessing is because we are ignoring the TYPE_VIEW_ACCESSIBILITY_FOCUSED event: https://stackoverflow.com/a/64703579/10173087.
This was a close one but didn't work because when the SeekBar is selected I need it to read something.
this solution, but I don't think there is an action to modify the SeekBar label, as we have here on the button: https://stackoverflow.com/a/41496367
Might not be 100% relevant because this is the solution for a compose component, but you can remove the percent readout by changing the stateDescription
modifier = Modifier
.semantics {
stateDescription = [your state]
}
Related
I have a button in Android which has text "Next" written on it.
when, I have the accsessibility cursor focus on the button, it reads out "Next button". This is something I don't want. I want whenever, the cursor to have focus on the "Next" button, it must read out as "Next button. Double tap to select". This I can easily do, by setting the
btn.contentDescription("Next button. Double tap to select"),
but then it reads out as
"Next button. Double tap to select button", means it additionally reads out the last button, which seems very odd, with the "button" text getting read twice.
Is there any way, by which I can stop the last button to be announced?
You're trying to do things that are the responsibility of the AT. The AT knows that the object is a button due to its class type. The AT knows that it is clickable, because Clickable is a valid accessibility action.
TalkBack will then share this information, here is the breakdown:
"Next button, (pause) double tap to select"
"Next" -> Content Description/Text. This is the part you control.
"Button" -> Calculated in TalkBack based off of the valid actions and type(class) of the object.
"Double tap to select" -> This announcement is based off of Clickable being a valid accessibility action.
SO, when you set the contentdescription to "Next ....." you end up with an announcement of "next ....... button (pause) double tap to select" and no, there is no way to override this.
IF you are absolutely intent on making your app less accessible, you could create a custom control, write your own gesture recognizers (as in not using "onClick" events, because this would make your element accessibility clickable) to recognize tap gestures. And then write your own content description, that includes name, role, and instructions yourself.
This would be very silly in my opinion! Just let the content-description be "next" and let TalkBack tell users that your element is a button and how to interact with it. While perhaps not the "perfect" wording you/whoever this requirement came from's vision. It will be the way TalkBack users are accustomed to having this type of control announced. Consistency is sometimes more important than having things "just so".
I know I'm way late to the game, but posting an answer here for anyone that may happen to come across this post.
The others are right... we should not be putting the type of widget or how to interact with the widget in the content description. However, all is not lost.
Starting with API 21, there is a way to customize the interaction text through AccessibilityNodeInfo. You can use this class in two different ways:
AccessibilityNodeInfo has a getActionList() method. You can add customize the text that is read out by TalkBack by adding a new item to that list:
info.getActionList().add(new AccessibilityNodeInfo.AccessibilityAction(AccessibilityAction.ACTION_CLICK, "select");
The above code should change "Double-tap to activate" to "Double-tap to select". I say should because I'm just writing that code from memory... I haven't verified it's 100% correct, but it should be something along those lines.
There are two ways to utilize that class, and the one you choose is going to depend on your situation.
Method 1: Subclass your view:
If you create a subclass of the view you are using (in the case of the OP it would be a subclass of Button) then you can override the onInitializeAccessibilityNodeInfo() method and put the code there.
Documentation: https://developer.android.com/reference/android/view/View.html#onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo)
Method 2: Create a view accessibility delegate
This can be a bit more tricky and involved, but it does offer a ton of flexibility because you don't have to subclass the views you are working with.
Every view has a method that allows you to set an accessibility delegate, which acts like a man-in-the-middle and you can tweak things for accessibility purposes before the info goes to TalkBack.
Documentation: https://developer.android.com/reference/android/view/View.html#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)
So basically you create a subclass of View.AccessibilityDelegate and override it's onInitializeAccessibilityNodeInfo() method with the code I posted above.
Documentation: https://developer.android.com/reference/android/view/View.AccessibilityDelegate.html#onInitializeAccessibilityNodeInfo(android.view.View,%20android.view.accessibility.AccessibilityNodeInfo)
Last but not least...
I did come across a way to stop the "Double tap to activate" text from being spoken out by Talkback. This should only be used when it really does make sense to remove it.
I repeat... this is not normally something you want to do.
I did recently come across a case where it made sense. I was using a TabLayout, and I noticed that Talkback would always read out "Double-tap to select" when the focus was on the selected tab (yes, I had used the method described above to change the text). Well... we don't want to tell the user to select a tab that is already selected, especially when the action results in a no-op. So, I used this little trick to get rid of that, but only for the currently selected tab. I left the unselected tabs alone so that Talkback would still give them the interaction text.
In your onInitializeAccessibilityNodeInfo() method, you can put the following code to remove that text:
info.addAction(AccessibilityNodeInfo.ACTION_FOCUS);
Again, I'm writing this code from memory, so I don't know if that's 100% there, but it gives you the gist of what to do.
Try to uncheck the setting in TalkBack -> verbosity -> speak element type -> uncheck. Now talkback will not announce class type of view at end of content description.
What you want to do is employ android:hint to provide information on inputting information (instead of adding it to the label).
Your label would be "Next" (either using labelFor with an onscreen label or android:contentDescription for hidden labeling)
Then your hint would be "Double tap to select" (using android:hint)
As the title says, I was wondering if there is a way to add a way to create input in my Android application, by providing the user with a bar similar to the one used by Android system for adjusting the sound volume. A specific variable would change its value, according to the position of a "button" on the bar (sorry for my English). Any advice on that?
A SeekBar is what you are looking for.
Here is the design spec: https://www.google.com/design/spec/components/sliders.html#
Here is the reference page: http://developer.android.com/reference/android/widget/SeekBar.html
If you want to set the value of the position of the SeekBar, simply do:
seekBar.setProgress(position);
where position is where you want the SeekBar to be.
Getting the position of the SeekBar is a bit more involved. Firstly you must set a setOnSeekBarChangeListener and grab the SeekBar value from within the onProgressChanged method. This is a StackOverflow question that answers this well: get android seekbar value and display it on screen
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?
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)
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
I have a custom view that extends EditText that has ToggleButtons for rich text editing. If I allow autocomplete, which I want to do, the indicator for the current word triggers my detection for style spans.
For example on most devices the autocorrect eligible word is an underline. As you type I have a text watcher that keeps track of the current styles that are applied to the text and adds new spannables if the user toggles a style button. This ends up detecting the underline and turning the toggle on.
I can write code to check if the underline toggle was set before we found the span. (I would actually need to do this for all my styles really since some devices use a background color to indicate the current autocorrect word.) But I'm unsure what I would use to trigger turning the toggle back to off. Check if they typed space? What happens when you select a suggested word?
Has anyone done this? Is there a way to ask if the span is from autocomplete or any other notifications to know the OS drew the span?
This is an old question, but just now I had a similar problem, namely eliminating the unwanted underline before converting the spans into HTML. I found the answer in the source to TextView.
There is a method TextView#clearComposingText() that will remove all styles applied by the IME during autosuggest, preserving all other styles. You could likely call it after every user keystroke, which would remove the underlines.
Hope this helps someone.
I have gone through many questions, API demo regarding Accessibility feature in Android but it couldn't help.
I want to support Accessibility in my Android application. Inbuilt Accessibility is taking care of all the focusable items and reads out the Hints correctly when clicked.
I want to fire Accessibility events whenever user clicks on TextView.And the first time the screen is opened, I want it to read out custom information which I provide. I have managed to do it with dispatchPopulateAccessibilityEvent but it reads everytime when screen is resumed. Also I can not identify which view is sending the event.
You can use the call "sendAccessibilityEvent", from within your TextView, like this:
if (AccessibilityManager.getInstance(mContext).isEnabled()) {
setContentDescription("The content description for this view");
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
The text read off (depending on which Accessibility Service is being used) will be based off the content description, not necessarily the text in the TextView.
If you want your view to be focused and annouce associated content description for that view then, You can use,
view.requestFocus()
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
If you just want to announce the change once only and don't want to change contentDescription associated with that view, you can use
view.announceForAccessibility = "Alert to a user about some event."
Note: announceForAccessibility will not get accessibility focus on your view.
You can use the
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
On your TextView, also you can add the "announceForAccessibility" but you should validation if the version is greater or equals than Jelly Bean but for that you need a change on the view.
Finally if you want to announce the "title" of the page, for example, the activity you could add the setTitle for the activity and put your text, remember use a Toolbar with a title because this setTitle by default will override the action bar title.
Let me know if you have any other issue.