[英]Accessible star rating for Android
我最近将 RatingBar 视图包含到布局中,并意识到它与 Talkback 不兼容(它不可访问)。 我怎样才能拥有考虑到 Talkback 用户的星级评分视图?
这里有一些想法,供所有来到这里的其他人参考。 我正在使用 targetSdk=28 和 androidx 库。
问题 1:当通告 ViewGroup 中的内容时,Talkback 会跳过 RatingBar。
解决方案:添加带有所需公告的 TextView。 将其设置为 0dp,这样就不会影响您的布局。 INVISIBLE 或 GONE 将不起作用。
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:text="4.1 of 5 stars"/>
解决方案:显示评分数,并在contentDescription中加上star。 (尽管以编程方式进行)
<TextView
android:id="@+id/ratingCountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23"
android:contentDescription="4.1 of 5 stars from 23 users"/>
问题 2:点击 RatingBar 以听取值。 contentDescription 在这种情况下有效,您可以在代码中设置它。
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3.5"
android:stepSize="1"
android:contentDescription="4.1 of 5 stars"/>
点击并拖动 RatingBar 以更改值似乎有效。 它说20%、40%、60%。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.