Accessibility Bugs in Android Dialogs and Bottom Sheets

1 min

Background

I recently had to add accessibility support (TalkBack) to my company’s product. The implementation on regular screens was fairly straightforward.

However, I encountered a very strange reading order issue when dealing with Dialogs and Bottom Sheets.

For some reason, when a Dialog or Bottom Sheet is open, the screen reader always starts by reading the very first element it finds in the top-left corner of the entire view. After a long search, I finally discovered that the decorView of the dialog also has its own accessibility settings.

How I Fixed It

NOTE

The solution was to clear the accessibility settings of the decorView during the Dialog’s onCreate stage.

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
      val dialog = super.onCreateDialog(savedInstanceState)
      dialog.window?.decorView?.importantForAccessibility = 
        View.IMPORTANT_FOR_ACCESSIBILITY_NO
      return dialog
}

After setting this, the initial focus state when the page opens becomes slightly slower.

Comments

Loading comments...