我想在激活话语提示时将ActionBar的Title and subtile分组,同时保持顺序相同:下一个backButton(标题+ SubTitle)下一个menuItems
我考虑过但不适合我的解决方案/解决方法:
创建两个TextView并与工具栏重叠(这里的问题是,它会弄乱顺序,BackButton,下一个menuItems,下一个(标题+子标题)]]
在ToolBar上设置contentDescription,这样看起来就像将Title和subTitle分组在一起,这里的问题是再次读取顺序(Title + SubTitle),将首先读取,接下来是backButton,接下来是ItemMenu
关于如何对工具栏的标题和子标题进行分组的其他想法?
// 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);
这不是完成此操作的可靠方法。唯一可靠的方法是建立自己的标题栏。 Android操作系统可以随时覆盖您设置的任何AccessibilityDelegate。不幸的是,没有支持Android API的方法!