适用于 Android TV 的无障碍功能最佳实践
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本指南提供了有关 Android TV 上无障碍功能的最佳实践,并针对原生应用和非原生应用提供了建议。
无障碍功能对我的电视应用为何如此重要?
在电视观看人群中,视力障碍并不罕见。
根据世界卫生组织 (WHO) 的数据,全球估计有 22 亿人患有视力障碍。根据 2018 年全国健康访问调查,在美国,有 3,200 万年满 18 周岁的美国人曾出现严重视力障碍。欧洲盲人联盟 (EBU) 估计,欧洲有 3,000 万盲人和部分视力障碍人士。
最重要的是,视力障碍用户可以像完全正常的同伴一样享受媒体内容。Comcast 委托开展的2017 年调查显示,96% 的盲人或视力不佳者经常观看电视,其中 81% 的人每天观看电视的时间超过 1 小时。不过,65% 的受访者还表示,他们在查找电视节目时遇到了问题。在2020 年英国的一项调查中,80% 的残障人士表示,他们在视频点播流媒体服务方面遇到过无障碍功能问题。
虽然辅助技术可以帮助弱视用户,但对于电视应用来说,在内容发现过程中支持无障碍功能非常重要。例如,请特别注意提供导航指南和正确标记元素,并确保电视应用能够与 TalkBack 等无障碍功能完美搭配使用。这些步骤可显著改善视障用户的体验。
提高无障碍功能的第一步是提高意识。本指南可帮助您和您的团队发现电视应用中的无障碍问题。
Android 无障碍功能资源
如需详细了解 Android 上的无障碍功能,请参阅我们的无障碍功能开发资源。
文字缩放
Android TV 应用应通过支持不同的像素密度来尊重用户对文本缩放的偏好。
请特别注意以下事项:
您可以使用以下命令更改文本缩放比例:
adb shell settings put system font_scale 1.2f
在 Android 12 及更高版本中,用户可以在设备设置中更改文字缩放比例。
键盘布局
在 Android 13(API 级别 33)及更高版本中,您可以使用 getKeyCodeForKeyLocation()
来查找预期按键位置的键码。如果用户重新映射了某些按键位置,或者使用的是布局不典型的键盘,则可能需要执行此操作。
语音描述
在 Android 13(API 级别 33)及更高版本中,用户可以通过新的系统级无障碍功能偏好设置跨所有应用启用音频说明。Android TV 应用可以通过使用 isAudioDescriptionRequested()
查询用户偏好设置。
Kotlin
private lateinit var accessibilityManager: AccessibilityManager
// In onCreate():
accessibilityManager = getSystemService(AccessibilityManager::class.java)
// Where your media player is initialized
if (am.isAudioDescriptionRequested) {
// User has requested to enable audio descriptions
}
Java
private AccessibilityManager accessibilityManager;
// In onCreate():
accessibilityManager = getSystemService(AccessibilityManager.class);
// Where your media player is initialized
if(accessibilityManager.isAudioDescriptionRequested()) {
// User has requested to enable audio descriptions
}
Android TV 应用可以通过向 AccessibilityManager
添加监听器来监控用户的偏好设置何时发生变化:
Kotlin
private val listener =
AccessibilityManager.AudioDescriptionRequestedChangeListener { enabled ->
// Preference changed; reflect its state in your media player
}
override fun onStart() {
super.onStart()
accessibilityManager.addAudioDescriptionRequestedChangeListener(mainExecutor, listener)
}
override fun onStop() {
super.onStop()
accessibilityManager.removeAudioDescriptionRequestedChangeListener(listener)
}
Java
private AccessibilityManager.AudioDescriptionRequestedChangeListener listener = enabled -> {
// Preference changed; reflect its state in your media player
};
@Override
protected void onStart() {
super.onStart();
accessibilityManager.addAudioDescriptionRequestedChangeListener(getMainExecutor(), listener);
}
@Override
protected void onStop() {
super.onStop();
accessibilityManager.removeAudioDescriptionRequestedChangeListener(listener);
}
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Accessibility best practices for Android TV\n\nThis guide provides best practices for accessibility on Android TV and provides\nrecommendations for both native and non-native apps.\n\nWhy is accessibility important for my TV app?\n---------------------------------------------\n\nVision impairments are not uncommon among the TV-watching population.\nAn estimated [2.2 billion people globally](https://www.who.int/health-topics/blindness-and-vision-loss#tab=tab_1)\nhave a vision impairment, according\nto the World Health Organization (WHO). In the US, 32 million Americans age 18 and older have experienced\nsignificant vision loss,\naccording to the [2018 National Health Interview Survey](https://www.afb.org/research-and-initiatives/statistics/adults).\nIn Europe, the estimates\npoint to [30 million](http://www.euroblind.org/about-blindness-and-partial-sight/facts-and-figures#:%7E:text=Statistics,sighted%20persons%20as%20blind%20persons)\nblind and partially sighted persons, according to the European Blind Union (EBU).\n\nMost importantly, users with vision impairments enjoy media content\njust as much as their fully sighted peers. A [2017 survey](https://www.afb.org/research-and-initiatives/statistics/adults) commissioned by Comcast\nshowed that 96% of users who are blind or have low vision regularly watch\nTV, with 81% watching more than an hour per day. However, 65% also reported\nencountering problems with looking up what's on TV. And in a [2020 survey in the\nUK](https://bighack.org/video-on-demand-streaming-and-accessibility-the-big-hack-survey-feedback/),\n80% of disabled people said they had experienced accessibility issues with video\non-demand streaming services.\n\nWhile assistive technologies can and do help users with low vision, it's\nimportant to support accessibility in content discovery journeys for TV apps.\nFor example, pay extra attention to providing navigation guidance and\nproperly labeling elements, and ensure that TV apps work well with accessibility\nfeatures like TalkBack. These steps can significantly improve the experience for\nusers with vision impairments.\n\nThe first step toward improving accessibility is awareness. This guide can\nhelp you and your team to uncover accessibility issues with your TV app.\n\n### Android accessibility resources\n\nTo learn more about accessibility on Android, see our [accessibility development resources](/guide/topics/ui/accessibility).\n\nText scaling\n------------\n\nAndroid TV apps should respect the user's preference for text scaling by [supporting different pixel densities](/training/multiscreen/screendensities#TaskUseDP).\n\nTake special care to:\n\n- Use `wrap_content` for dimensions in UI components.\n- Ensure that layouts rearrange components as their dimensions change depending on the text scale.\n- Ensure that components still fit on the screen at larger text scales.\n- Don't use sp text size units for components that are not flexible.\n- Check the value of `FONT_SCALE` for adjustment in custom views:\n\n // Checking font scale with Context\n val scale = resources.configuration.fontScale\n Log.d(TAG, \"Text scale is: \" + scale)\n\nThe text scale can be changed with the following command: \n\n adb shell settings put system font_scale 1.2f\n\nOn Android 12 and above, users can alter the text scaling from the device\nsettings.\n\nKeyboard layouts\n----------------\n\nIn Android 13 (API level 33) and higher, you can use\n[`getKeyCodeForKeyLocation()`](/reference/android/view/InputDevice#getKeyCodeForKeyLocation(int))\nto\n[look up the keycodes](/training/tv/games#keyboard-layouts) for\nexpected key locations.\nThis might be necessary if the user has re-mapped some key locations or if they\nare using a keyboard that does not have a typical layout.\n\nAudio description\n-----------------\n\nIn Android 13 (API level 33) and higher, a new system-wide accessibility preference\nlets users enable audio descriptions across all apps. Android TV apps can\ncheck the user's preference by querying it with\n[`isAudioDescriptionRequested()`](/reference/android/view/accessibility/AccessibilityManager#isAudioDescriptionRequested()). \n\n### Kotlin\n\n```kotlin\nprivate lateinit var accessibilityManager: AccessibilityManager\n\n// In onCreate():\naccessibilityManager = getSystemService(AccessibilityManager::class.java)\n\n// Where your media player is initialized\nif (am.isAudioDescriptionRequested) {\n // User has requested to enable audio descriptions\n}\n```\n\n### Java\n\n```java\nprivate AccessibilityManager accessibilityManager;\n\n// In onCreate():\naccessibilityManager = getSystemService(AccessibilityManager.class);\n\n// Where your media player is initialized\nif(accessibilityManager.isAudioDescriptionRequested()) {\n // User has requested to enable audio descriptions\n}\n```\n\nAndroid TV apps can monitor when a user's preference changes by\nadding a listener to\n[`AccessibilityManager`](/reference/android/view/accessibility/AccessibilityManager): \n\n### Kotlin\n\n```kotlin\nprivate val listener =\n AccessibilityManager.AudioDescriptionRequestedChangeListener { enabled -\u003e\n // Preference changed; reflect its state in your media player\n }\n\noverride fun onStart() {\n super.onStart()\n\n accessibilityManager.addAudioDescriptionRequestedChangeListener(mainExecutor, listener)\n}\n\noverride fun onStop() {\n super.onStop()\n\n accessibilityManager.removeAudioDescriptionRequestedChangeListener(listener)\n}\n```\n\n### Java\n\n```java\nprivate AccessibilityManager.AudioDescriptionRequestedChangeListener listener = enabled -\u003e {\n // Preference changed; reflect its state in your media player\n};\n\n@Override\nprotected void onStart() {\n super.onStart();\n\n accessibilityManager.addAudioDescriptionRequestedChangeListener(getMainExecutor(), listener);\n}\n\n@Override\nprotected void onStop() {\n super.onStop();\n\n accessibilityManager.removeAudioDescriptionRequestedChangeListener(listener);\n}\n```"]]