使用 TalkBack 时 Android focusable 和 importantForAccessibility 有什么区别?

What is the difference between Android focusable and importantForAccessibility when using TalkBack?

我注意到在很多情况下 android:importantForAccessibility="yes" 可以替换为 android:focusable="true",并且与 TalkBack 的工作方式完全相同。什么时候应该使用 android:importantForAccessibility="yes" 而不是使用 focusable?

Android 将 android:importantForAccessibility 定义为:

Describes whether or not this view is important for accessibility. If it is important, the view fires accessibility events and is reported to accessibility services that query the screen. Note: While not recommended, an accessibility service may decide to ignore this attribute and operate on all views in the view tree. https://developer.android.com/reference/android/view/View.html#attr_android:importantForAccessibility

android:focusable="true"为:

Controls whether a view can take focus. By default, this is "auto" which lets the framework determine whether a user can move focus to a view. By setting this attribute to true the view is allowed to take focus. By setting it to "false" the view will not take focus. This value does not impact the behavior of directly calling requestFocus(), which will always request focus regardless of this view. It only impacts where focus navigation will try to move focus. https://developer.android.com/reference/android/view/View.html#attr_android:focusable

Focusable 是指 "input focus" 和 "keyboard focus"。可聚焦控件是可以接收输入焦点(光标)或键盘焦点的控件...这基本上意味着用户可以使用 trackball/keyboard 导航来突出显示此类控件并与 "select" 进行交互操作...示例:按键盘上的回车键。

isImportantForAccessibility 指的是辅助功能焦点。这与输入焦点高度相关,但又非常不同。例如,输入聚焦 "informative" 纯文本内容是无意义的。然而,允许一个段落获得可访问性焦点是非常重要的。这允许使用 TalkBack 的用户集中注意力并听到此类信息控件的语音反馈。

如果用户使用键盘导航,输入焦点和辅助功能焦点将相同,但如果用户使用 TalkBack 滑动导航,输入焦点和辅助功能焦点可能不同。

例如:

光标可能位于 EditText 框中,而辅助功能焦点位于其下方的段落上,通过 VoiceFeedback 向用户解释该控件的用途。