使用 TextInputLayout 时辅助功能检查失败
Accessibility Check fail when using TextInputLayout
我正在使用 Android.support 提供的新 TextInputLayout 来做浮动标签。但它将无法通过 Espresso 可访问性检查,因为 "View is missing speakable text needed for a screen reader"。
调查并发现当父级执行 addView() 时,TextInputLayout 将取消提示。这基本上就是它如何使标签浮动(设置标签,使提示无效)。并且任何具有空提示的 EditText 都将无法通过可访问性检查。
有人知道如何解决这个问题吗?真的快把我逼疯了..
非常感谢!!!
一般而言,提示对于可访问性来说不是很好。输入文本时它们会消失。尝试使用 "LabelFor" 代替。如果您不想要可见的标签,可以将标签设置为不显示。
此应用程序将为您提供有关如何使文本框易于访问的提示。
https://play.google.com/store/apps/details?id=com.dequesystems.accessibility101
使 TextInputLayout 可访问的一个好方法是使用 "LabelFor",正如 ChrisCM 所推荐的那样,但您不必为此添加不可见的标签视图:只需将 labelFor
或您的 Textinputlayout
并使其指向您的 EditText
示例:
<android.support.design.widget.TextInputLayout
android:labelFor="@+id/username"
android:contentDescription="@string/username_hint"
android:accessibilityLiveRegion="polite">
<edittext
android:id="@+id/username"
android:hint="@string/username_hint"
…/>
</android.support.design.widget.TextInputLayout>
通过这种方式,您可以获得完全相同的视觉行为,并使 "Espresso Accessibility Check" 和 Talkback 快乐 :)
(为了使 TextInputLayout 完全可访问,我还在 TextInputLayout 元素上添加了 android:accessibilityliveregion
,以便在弹出错误时触发对讲)
非常感谢这个 post this blog post 帮助很大
或者,如果这是误报,您可以忽略检查 here
val validator: AccessibilityValidator = AccessibilityChecks.enable().apply {
setSuppressingResultMatcher(
allOf(
matchesCheckNames(`is`("TouchTargetSizeViewCheck")),
matchesViews(withId(R.id.my_overflow))
)
)}
当我们启用可访问性检查测试时,将调用以下规则:
- TouchTargetSizeViewCheck 目标高度或目标宽度小于 48
dp 被标记,除非检测到触摸委托。
- TextContrastViewCheck 检查文本颜色和背景以及因素
大文本,并计算对比度:- 常规为 4.5
文本,3 表示大文本。
- DuplicateSpeakableTextViewHierarchyCheck If
层次结构中的两个视图具有相同的可读文本,可以是
如果其中至少一个是可点击的,用户会感到困惑。
- SpeakableTextPresentViewCheck 如果视图可聚焦,则检查
是否存在有效的可读文本,如果视图是错误的
缺少屏幕所需的可读文本 reader。
- EditableContentDescViewCheck 如果 Editable TextView 有
内容描述。
- ClickableSpanViewCheck 检查是否有 ClickableSpan
无法访问。不能独立选择单个跨度
单个 TextView,无障碍服务无法调用
ClickableSpan#onClick。
- RedundantContentDescViewCheck 辅助功能
服务知道视图的类型并且可以使用该信息作为
需要。例如,如果内容描述不正确,它会发出警告
有一个多余的词,例如“按钮”。
- DuplicateClickableBoundsViewCheck 如果可点击视图则抛出错误
与另一个可点击视图(可能是后代)具有相同的边界。
有时会有标记为可点击的容器,但它们不会
处理任何点击事件。
您可以制作一个具有
的 TextView
android:text="My Announcement For Edit Text"
android:labelFor="@id/my_edit_text".
Visibility = gone
和 visibility = invisible
将使其不被公布。此外,如果您将高度和宽度设置为 0dp,则不会显示。相反,使用类似以下内容将视图限制在屏幕之外:
app:layout_constraintEnd_toStartOf="parent"
因此您的文本视图将如下所示:
<TextView
android:id="@+id/edit_text_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/my_edit_text"
android:text="Label For My Edit Text"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
这对我有用 withClassName
用于视图
AccessibilityChecks.enable().setSuppressingResultMatcher(
AccessibilityCheckResultUtils.matchesViews(
Matchers.anyOf(
ViewMatchers.withResourceName("textview1"),
ViewMatchers.withResourceName("button1"),
ViewMatchers.withClassName(Matchers.endsWith("TextInputLayout"))
)
)
)
我正在使用 Android.support 提供的新 TextInputLayout 来做浮动标签。但它将无法通过 Espresso 可访问性检查,因为 "View is missing speakable text needed for a screen reader"。
调查并发现当父级执行 addView() 时,TextInputLayout 将取消提示。这基本上就是它如何使标签浮动(设置标签,使提示无效)。并且任何具有空提示的 EditText 都将无法通过可访问性检查。
有人知道如何解决这个问题吗?真的快把我逼疯了..
非常感谢!!!
一般而言,提示对于可访问性来说不是很好。输入文本时它们会消失。尝试使用 "LabelFor" 代替。如果您不想要可见的标签,可以将标签设置为不显示。
此应用程序将为您提供有关如何使文本框易于访问的提示。
https://play.google.com/store/apps/details?id=com.dequesystems.accessibility101
使 TextInputLayout 可访问的一个好方法是使用 "LabelFor",正如 ChrisCM 所推荐的那样,但您不必为此添加不可见的标签视图:只需将 labelFor
或您的 Textinputlayout
并使其指向您的 EditText
示例:
<android.support.design.widget.TextInputLayout
android:labelFor="@+id/username"
android:contentDescription="@string/username_hint"
android:accessibilityLiveRegion="polite">
<edittext
android:id="@+id/username"
android:hint="@string/username_hint"
…/>
</android.support.design.widget.TextInputLayout>
通过这种方式,您可以获得完全相同的视觉行为,并使 "Espresso Accessibility Check" 和 Talkback 快乐 :)
(为了使 TextInputLayout 完全可访问,我还在 TextInputLayout 元素上添加了 android:accessibilityliveregion
,以便在弹出错误时触发对讲)
非常感谢这个 post this blog post 帮助很大
或者,如果这是误报,您可以忽略检查 here
val validator: AccessibilityValidator = AccessibilityChecks.enable().apply {
setSuppressingResultMatcher(
allOf(
matchesCheckNames(`is`("TouchTargetSizeViewCheck")),
matchesViews(withId(R.id.my_overflow))
)
)}
当我们启用可访问性检查测试时,将调用以下规则:
- TouchTargetSizeViewCheck 目标高度或目标宽度小于 48 dp 被标记,除非检测到触摸委托。
- TextContrastViewCheck 检查文本颜色和背景以及因素 大文本,并计算对比度:- 常规为 4.5 文本,3 表示大文本。
- DuplicateSpeakableTextViewHierarchyCheck If 层次结构中的两个视图具有相同的可读文本,可以是 如果其中至少一个是可点击的,用户会感到困惑。
- SpeakableTextPresentViewCheck 如果视图可聚焦,则检查 是否存在有效的可读文本,如果视图是错误的 缺少屏幕所需的可读文本 reader。
- EditableContentDescViewCheck 如果 Editable TextView 有 内容描述。
- ClickableSpanViewCheck 检查是否有 ClickableSpan 无法访问。不能独立选择单个跨度 单个 TextView,无障碍服务无法调用 ClickableSpan#onClick。
- RedundantContentDescViewCheck 辅助功能 服务知道视图的类型并且可以使用该信息作为 需要。例如,如果内容描述不正确,它会发出警告 有一个多余的词,例如“按钮”。
- DuplicateClickableBoundsViewCheck 如果可点击视图则抛出错误 与另一个可点击视图(可能是后代)具有相同的边界。 有时会有标记为可点击的容器,但它们不会 处理任何点击事件。
您可以制作一个具有
的 TextViewandroid:text="My Announcement For Edit Text"
android:labelFor="@id/my_edit_text".
Visibility = gone
和 visibility = invisible
将使其不被公布。此外,如果您将高度和宽度设置为 0dp,则不会显示。相反,使用类似以下内容将视图限制在屏幕之外:
app:layout_constraintEnd_toStartOf="parent"
因此您的文本视图将如下所示:
<TextView
android:id="@+id/edit_text_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/my_edit_text"
android:text="Label For My Edit Text"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
这对我有用 withClassName
用于视图
AccessibilityChecks.enable().setSuppressingResultMatcher(
AccessibilityCheckResultUtils.matchesViews(
Matchers.anyOf(
ViewMatchers.withResourceName("textview1"),
ViewMatchers.withResourceName("button1"),
ViewMatchers.withClassName(Matchers.endsWith("TextInputLayout"))
)
)
)