如何解决Android辅助功能在TextInputLayout中不起作用
如果在TextInputEditText中没有键入任何文本,则Android Accessibility对讲程序将读取TextInputLayout中的提示。
但是,如果在TextInputEditText中添加了文本,则Android Talkback将不会读取TextInputLayout中的提示。
我需要辅助功能对讲以便始终阅读TextInputLayout中的提示。
有人知道怎么做吗?
谢谢大家
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:labelFor="@+id/editText"
android:hint="username">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
解决方法
将其覆盖为的唯一方法:
扩展:
public class CustomTextInputLayoutAccessibilityDelegate extends TextInputLayout.AccessibilityDelegate {...}
然后覆盖:
public void onInitializeAccessibilityNodeInfo(View host,AccessibilityNodeInfoCompat info) {
...
// And add the new logic in here:
if (showingText) {
if (hasHint) {
info.setText(String.format("%s,%s",hintText,text));
} else {
info.setText(text);
}
} else if (hasHint) {
info.setText(hintText);
}
}
并将其设置为您的TextInputLayout为:
setTextInputAccessibilityDelegate(new CustomTextInputLayoutAccessibilityDelegate(this));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。