如何让 TalkBack 忽略 android:text 元素?

How can I make TalkBack ignore android:text element?

我正在改进我的 android 应用程序中视障人士的辅助功能。我的 Android 项目的 popover.xml 文件中有以下 TextView。

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="12dp"
    android:text="@string/pass_code"/>

每当我使用 TalkBack 测试应用程序时,应用程序都会说出 android:text 中的字符串,但在这种情况下,我根本不希望它被说出,因为这是一个弹出窗口 window所以我宁愿希望 window 弹出时立即说出来。所以我的根 LinearLayout 中有 android:contentDescription="@string/pass_code",它说出相同的字符串。

我试过设置 android:contentDescription="@null" 并且我也试过添加 tools:ignore="ContentDescription" 但它们都不起作用。 android:text 中的元素总是被读出。如何更改 TextView 以便 TalkBack 忽略 android:text 元素?

您可以通过在布局 XML 中设置 android:importantForAccessibility="no" 来隐藏无障碍服务的视图。有关详细信息,请参阅 View.setImportantForAccessibility(int) 的开发人员文档。