Android Talkback未自动播报选中状态问题求助
The core issue is that Talkback relies on the view's actual selected state (via the isSelected property) to automatically prepend the "selected" prefix—not just sending a TYPE_VIEW_SELECTED accessibility event. Here's how to resolve it:
Mark the selected view as truly selected
Before triggering accessibility focus, ensure the target view has itsisSelectedproperty set totrue, and all other BottomSheet items are set tofalse. This explicitly tells Talkback the view's state.// Example: When initializing or updating BottomSheet selection bottomSheetItemContainer.children.forEach { itemView -> itemView.isSelected = itemView == selectedView }Simplify the accessibility focus logic
Once the view's selected state is correctly set, redundant events aren't necessary. Focusing the view and sending the appropriate accessibility event will let Talkback announce the state automatically.Update your extension function:
private fun View.accessibilityFocus(): View { this.requestFocus() this.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null) // This event will include the selected state if isSelected is true this.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) return this }Adjust the delayed call
Keep your existing delayed invocation, but ensure theisSelectedstate is set before callingaccessibilityFocus():if (isCurrentlySelectedTab) { // Set selected state first selectedView.isSelected = true // Optional: Unselect other items here if not handled earlier uiHandler.postDelayed( { selectedView.accessibilityFocus() }, ACCESSIBILITY_DELAY, ) }
This works because Talkback checks the view's isSelected flag when processing accessibility events. If the flag is true, it automatically adds the "selected" prefix to the content description without manual hardcoding.
内容的提问来源于stack exchange,提问作者Subodh Nijsure

