辅助功能:对讲、WebView 和用户的语言环境 [英] Accessibility: Talkback, WebView and user's locale

查看:30
本文介绍了辅助功能:对讲、WebView 和用户的语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个包含 Web 视图的应用.我想让我的应用程序完全可访问,因此对于 webview 元素,我希望 TalkBack 以完全可访问的方式读取 html 元素,例如标题"、横幅"、EditText".

I have developed an app that includes a 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中的TTS过程是通过Chromium AccessibilityInjector.java类通过JS注入完成的.这会将这个脚本注入到只有英文消息的页面中.结果是,当设备使用另一种语言时,TTS 无论如何都会以英文读取这些 html 元素.

I have seen that the TTS process in WebView is done through JS injection via Chromium AccessibilityInjector.java class. 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.

现在我无法调试或扩展chromium webclient,那么如何让TTS根据用户的语言环境读取我的页面?

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?

顺便说一下,我正在使用 jQuery Mobile.

I am using jQuery Mobile by the way.

推荐答案

以防万一有人偶然发现这个问题:我不得不应用一个丑陋的解决方法来解决这个问题.每当我加载页面并启用 TalkBack 时,我都会重新注入包含要读取的文本的 javascript 变量及其本地化对应项.例如,对于西班牙语文本:

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. 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)");

请注意,我在注入变量之前插入了一个超时——这是为了防止 chromevox 在我注入之后被注入,从而使解决方案无用.

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.

我知道这是一个丑陋的补丁,但如果无法访问 Chromium webview 类,我找不到任何更好的解决方案.

I know this is an ugly patch, but I could not find any better solutions without access to the chromium webview classes.

这篇关于辅助功能:对讲、WebView 和用户的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆