androidtalkbackaccessibility

Toolbar content description didn't work as expected


I am setting contentDescription to a toolbar in Fragment and DialogFragment class.

In Fragment class, It works fine. (e.g.

  1. on toolbar focused,"toolbarContentDescription"
  2. on next swipe forward, "Navigation Up"
  3. on next swipe backward, "toolbarContentDescription")

In DialogFragment class, It reads navigation up first. (e.g.

  1. on toolbar focused, "Navigation Up toolbarContentDescription"
  2. on next swipe forward, "Navigation Up"
  3. on next swipe backward, "toolbarContentDescription")

I am using the same code to set toolbar in both classes.

I tried to fix it by changing the position of navigationContentDescription. But it didn't work in dialogFragment class. and If I remove navigationContentDescription, on the back arrow it will read "Unlabeled Botton".

fun setToolBar(toolbar: Toolbar, title: String) {
    getMainActivity().setSupportActionBar(toolbar)
    toolbar.title = title
    toolbar.contentDescription = "toolbar content description here"
    toolbar.setTitleTextAppearance(context, R.style.white_toolbar_text)
    toolbar.setBackgroundColor(ContextCompat.getColor(context, R.color.white))

    toolbar.setNavigationIcon(R.drawable.ic_back_arrow)
    // set back arrow content description.
    toolbar.navigationContentDescription  = "Navigation Up"
    toolbar.setNavigationOnClickListener {
                getMainActivity().onBackPressed()
        }

    toolbar.requestFocus()
toolbar.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}

I don't understand the reason for this different behavior. It should read the same toolbar description as a fragment class in dialog fragment.


Solution

  • TalkBack has a special treat to Dialog screens. In every dialog, the screen reader makes a special announcement of its title. I don't think you will be able to change this behavior, since it is not in your app scope, but in the TalkBack implementation itself.