Android TalkBack and fragment stack

前端 未结 6 1833
迷失自我
迷失自我 2021-01-11 17:14

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,

6条回答
  •  情书的邮戳
    2021-01-11 17:47

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

提交回复
热议问题