Android TalkBack and fragment stack

前端 未结 6 1832
迷失自我
迷失自我 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:55

    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.

提交回复
热议问题