0

I would like to group ActionBar's Title and subtile when TalkBack is activated while keeping the order the same: backButton next (title + SubTitle) next menuItems

The solutions/workaround I thought about but didn't work for me:

  • Create two TextView and overlap the toolbar (the issue here, it will muss up the order, BackButton, next menuItems, next (title + subTitle))

  • Set the contentDescription on ToolBar that way it will look like the Title and subTitle were grouped together, the issue here is again the order (Title + SubTitle) will be read first, next backButton, next ItemMenu

Any other ideas to how to group the title + subTitle of Toolbar ?

M'hamed
  • 2,508
  • 3
  • 24
  • 41

1 Answers1

0

You can't do this. Or rather, you can't do this with the default Activity apis, doing so involves significant hackery.

If you really want to do this, here is some almost working code, that I admitadely didn't actually run, but that should put you on the right path.

// Find the View you want to represent the complete title subtitle combination.
// As well as the individual views for title and subtitle
View groupedView = findTheTitleBarView();
View subTitleView = propbablyAChildOfGroupedView;
View titleView = propbablyAChildOfGroupedView;

ViewCompat.setAccessibilityDelegate(groupedView, object : AccessibilityDelegateCompat() {
    override fun onInitializeAccessibilityNodeInfo(
        host: View?,
        info: AccessibilityNodeInfoCompat?
    ) {
        info?.text = subTitleView.text() + " " + titleView.text();
        super.onInitializeAccessibilityNodeInfo(host, info)
    }
})

// Ensure the children of those views are not individually focusable.

titleView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
subtitleView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);

This is not a reliable way of accomplishing this. The only reliable way to do this would be to build your own title bar. The Android OS can override whatever AccessibilityDelegate you set whenever it wants. Unfortunately there is no Android API supported way to do this!

MobA11y
  • 18,425
  • 3
  • 49
  • 76