For an application that I work on, I need to implement accessibility. Everything works fine except for one screen where I have to fragments added to my activity. Basically, the fragment that is above is a dial keyboard to enter a passcode. This fragment is added with a fragmentTransaction.
The thing is that the talkback focus is set on the elements of the underneath fragment.
Do you know if there is a way to set the talkback focus on the dial fragment ? I just want to "disable" the fragment underneath to get focus
Thanks,
Calling addToBackStack() commits the transaction to the back stack. The user can later reverse the transaction and bring back the previous fragment by pressing the Back button. If you added or removed multiple fragments within a single transaction, all of those operations are undone when the back stack is popped.
A Fragment is a combination of an XML layout file and a java class much like an Activity . Using the support library, fragments are supported back to all relevant Android versions.
A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.
Types of Fragments Basically fragments are divided as three stages as shown below. Single frame fragments − Single frame fragments are using for hand hold devices like mobiles, here we can show only one fragment as a view. Fragments transaction − Using with fragment transaction.
Are you using fragmentTransaction.add?
If so you sould use fragmentTransaction.replace!
Add function also did problems with clicking the below fragment views.
So please, use replace.
UPDATE
I figured out the solution. you can disable the accessibility of the first fragment before you do the fragment transaction.
rootView = inflater.inflate(R.layout.first_fragment, null, false);
rootView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
and now you commit your fragment transaction. Second fragment won't leak the focus to first fragment.
Don't forget to enable the accessibility of first fragment in case you're coming back to the first fragment.
if(rootView != null) {
rootView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
}
Your problem isn't "sending" focus to the correct place. Forcing focus around to different places is generally a bad idea, and inaccessible. Your problem is that you have elements on the screen that aren't visible, but are being focused by TalkBack. What you want to do is hide these elements from TalkBack. Actually, you probably want to remove them completely, but let's assume that they need to be on the screen. What you can do is hide them from the accessibility service:
rootViewOfFragment.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
This will hide those views from TalkBack. This is a better solution than forcing focus to a specific element, as this is generally an accessibility violation under WCag 2.0. Though if the elements on screen are not completely hidden by your "top" fragment, this is also a violation, and you should actually just leave things be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With