Search code examples
androidandroid-fragmentsfragmentaccessibilitytalkback

Android TalkBack and fragment stack


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,


Solution

  • 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);
    }