[英]Samsung S10+ Accessibility View Focus Issues with TalkBack on
我有一个视图,用户可以在其中输入目标、完成目标的日期和确认复选框。 用户必须输入所有这些才能继续前进。 因此,我检查是否有任何字段为空。 这是代码。 此代码有效。
private fun toggleInputRequiredError(
isErrorVisible: Boolean,
view: TextInputLayout,
errorText: String
) {
when (isErrorVisible) {
true -> {
view.error = errorText
}
else -> view.error = null
}
}
toggleInputRequiredError(
!state.isGoalChecked,
goalAffirmationCheckBoxErrorContainer,
getString(R.string.required_field)
).run {
if (!state.isGoalChecked) {
goalAffirmationCheckBox.isFocusable = true
goalAffirmationCheckBox.requestFocus()
goalAffirmationCheckBox.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
}
toggleInputRequiredError(
!state.isValidDateInput,
goalDateInputLayout,
getString(R.string.required_field)
).run {
if (!state.isValidDateInput) {
goalCompletionDateInput.isFocusable = true
goalCompletionDateInput.requestFocus()
goalCompletionDateInput.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
}
toggleInputRequiredError(
!state.isValidDescriptionInput,
goalDescriptionInputLayout,
getString(R.string.required_field)
).run {
if( !state.isValidDescriptionInput) {
goalDescriptionInput.isFocusable = true
goalDescriptionInput.requestFocus()
goalDescriptionInput.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
}
现在,除了最新的三星手机外,我必须在大多数手机上启用此视图的可访问性。 Pixel XL 和三星 S8 都体现了所需的行为。 这是显示此内容的图像
在较新的三星上, sendAccessibilityEvent似乎并没有真正关注需要解决的视图。 这是一张图片,展示了三星 S10+ 和三星 Note 9 上的这种行为。
我在XML中设置了这些视图的内容描述。 我注意到较新的三星手机会阅读屏幕上的“必填”文本,但不会专注于它。 这意味着它忽略了 XML 中的内容描述。 最后就是需要对焦的view好像没有遇到sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)事件
让我知道您是否对如何解决此问题有任何想法,或者如果您有任何建议我可以尝试
在三星 S10 设备中,我无法将辅助功能焦点设置为自定义视图。 然后我已经基于以下代码实现了,所以可以在你的关注下尝试这个,也许它会有所帮助。
val task = Runnable {
val mA11yManager = context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
if (mA11yManager.isEnabled) {
// Equivalent to ACTION_ACCESSIBILITY_FOCUS
plus_chip_text?.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
// we fire selection events here not in View
plus_chip_text?.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED)
}
}
val worker: ScheduledExecutorService = newSingleThreadScheduledExecutor()
worker.schedule(task, 1, TimeUnit.SECONDS)
抱歉,我知道这是差不多一年后的事了,但我们在运行 Android 10 的三星 Talkback 上发现了一个非常相似的问题。它可以在早期版本的 Android 上正常工作。
我们发现创建以下 kotlin 扩展 function 似乎适用于所有版本的 Android,并且适用于三星语音助手和对讲。
希望这能够帮助其他面临类似问题的人。
fun View?.requestAccessibilityFocus(): View? {
this?.performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null)
this?.sendAccessibilityEvent(TYPE_VIEW_SELECTED)
return this
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.