简体   繁体   English

Android 的无障碍星级评分

[英]Accessible star rating for Android

I recently included the RatingBar view into a layout and realized it is not compatible with Talkback (it is not accessible).我最近将 RatingBar 视图包含到布局中,并意识到它与 Talkback 不兼容(它不可访问)。 How can I have a star rating view that takes into account Talkback users?我怎样才能拥有考虑到 Talkback 用户的星级评分视图?

Here are some ideas for anyone else who ends up here.这里有一些想法,供所有来到这里的其他人参考。 I'm using targetSdk=28 and the androidx libraries.我正在使用 targetSdk=28 和 androidx 库。

Problem 1: Talkback skips the RatingBar when announcing the content in a ViewGroup.问题 1:当通告 ViewGroup 中的内容时,Talkback 会跳过 RatingBar。

Solution: Add a TextView with the desired announcement.解决方案:添加带有所需公告的 TextView。 Make it 0dp, so it won't affect your layout.将其设置为 0dp,这样就不会影响您的布局。 INVISIBLE or GONE won't work. INVISIBLE 或 GONE 将不起作用。

<TextView
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:text="4.1 of 5 stars"/>

Solution: Display the number of ratings, and add the stars to the contentDescription.解决方案:显示评分数,并在contentDescription中加上star。 (do it programmatically, though) (尽管以编程方式进行)

<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"/>

Problem 2: Tapping on a RatingBar to hear the value.问题 2:点击 RatingBar 以听取值。 contentDescription works in this case, and you can set it in code. 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"/>

Tapping and dragging on a RatingBar to change the value seems to work.点击并拖动 RatingBar 以更改值似乎有效。 It says 20%, 40%, 60%.它说20%、40%、60%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM