简体   繁体   English

辅助功能:对讲,WebView和用户的语言环境

[英]Accessibility: Talkback, WebView and user's locale

I have developed an app that includes a Webview. 我开发了一个包含Webview的应用程序。 I would like to make my app fully accessible, so for the webview element I would like for TalkBack to read html elements such as "Heading", "Banner", "EditText" in a fully accessible way. 我想让我的应用程序完全可访问,因此对于webview元素,我希望TalkBack以完全可访问的方式读取诸如“标题”,“横幅”,“EditText”等html元素。

I have seen that the TTS process in WebView is done through JS injection via Chromium AccessibilityInjector.java class. 我已经看到WebView中的TTS过程是通过Chromium AccessibilityInjector.java类通过JS注入完成的。 This injects this script into the page, which only has the messages in English. 这会将此脚本注入到页面中,该页面仅包含英文消息。 The result is that when a device is in another language, the TTS reads these html element in English regardless. 结果是当设备使用另一种语言时,TTS会用英语读取这些html元素。

Now I cannot debug or extend the chromium webclient, so how can I make TTS to read my page according to the user's locale? 现在我无法调试或扩展chrome webclient,那么如何根据用户的语言环境使TTS读取我的页面?

EDIT: I am using jQuery Mobile by the way. 编辑:顺便说一句,我正在使用jQuery Mobile。

Just in case someone stumbles into this problem: I had to apply an ugly workaround to get over this. 万一有人偶然发现这个问题:我不得不应用一个丑陋的解决方法来克服这个问题。 Whenever I load a page and TalkBack is enabled, I reinject the javascript variables containing the text to be read, with their localized counterparts. 每当我加载页面并启用TalkBack时,我会重新注入包含要读取的文本的javascript变量及其本地化对应项。 For instance, for Spanish text: 例如,对于西班牙文本:

view.loadUrl("javascript:window.setTimeout(function(){" +
                "window.console.log(\"Injecting messages.\");" +
                "cvox.TestMessages[\"chromevox_input_type_text\"] = {message: \"cuadro de edición\"};" +
                "cvox.TestMessages[\"chromevox_input_type_radio\"] = {message: \"botón de opción\"};" +
                "cvox.TestMessages[\"chromevox_selected\"] = {message: \"seleccionado\"};" +
                "cvox.TestMessages[\"chromevox_unselected\"] = {message: \"no seleccionado\"};" +
                "cvox.TestMessages[\"chromevox_radio_selected_state\"] = {message: \"seleccionado\"};" +
                "cvox.TestMessages[\"chromevox_radio_unselected_state\"] = {message: \"no seleccionado\"};" +
                "cvox.TestMessages[\"chromevox_input_type_submit\"] = {message: \"botón\"};" +
                "cvox.TestMessages[\"chromevox_input_type_button\"] = {message: \"botón\"};" +
                "cvox.TestMessages[\"chromevox_tag_button\"] = {message: \"botón\"};" +
                "}, 2000)");

Note that I insert a timeout before injecting the variables -- this is to prevent chromevox from being injected after my injection thus making the solution useless. 请注意,我在注入变量之前插入超时 - 这是为了防止在注入注入chromevox,从而使解决方案无效。

I know this is an ugly patch, but I could not find any better solutions without access to the chromium webview classes. 我知道这是一个丑陋的补丁,但是如果没有访问chrome webview类,我找不到更好的解决方案。

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

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