Android-WebView语言在Android 7.0及更高版本上突然改变 [英] Android - WebView language changes abruptly on Android 7.0 and above

查看:136
本文介绍了Android-WebView语言在Android 7.0及更高版本上突然改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用多种语言的应用程序,其中包含主要语言的英语和次要语言的阿拉伯语.

I have a multilingual app with primary language English and secondary language Arabic.

文档中所述,

  • 我已在清单中添加了android:supportsRtl="true".
  • 我已将所有具有leftright属性的xml属性分别更改为startend.
  • 我已经在strings-ar中添加了阿拉伯语言字符串(对于其他资源也是如此).
  • I have added android:supportsRtl="true" in the manifest.
  • I have changed all xml properties with left and right attributes to start and end respectively.
  • I have added Arabic language strings in strings-ar (and similarly for other resources).

以上设置正常运行.将Locale更改为ar-AE后,阿拉伯文字&资源正确显示在我的活动中.

The above setup works properly. After changing the Locale to ar-AE, Arabic text & resources are correctly displayed in my Activities.

但是,每次我使用WebView导航到Activity 和/或WebViewClient,语言环境,文本和布局方向 突然恢复为设备默认值.

However, every time I navigate to an Activity with a WebView and/or a WebViewClient, the locale, text and layout direction abruptly revert to the device default.

其他提示:

  • 这是在具有 Android 7.0 的Nexus 6P上 发生的.一切都可以在Android 6.0.1及更低版本上正常运行.
  • 当我导航到具有WebView和/或WebViewClientActivity时,语言环境的突然变化只发生 (并且我有几个).在其他任何活动中都不会发生.
  • This is occurring only on a Nexus 6P with Android 7.0. Everything works properly on Android 6.0.1 and below.
  • The abrupt shift in locale happens only when I navigate to an Activity that has a WebView and/or a WebViewClient (and I have several). It does not occur on any of the other Activities.

Android 7.0具有多语言环境支持,允许用户设置多个默认语言环境.因此,如果我将主要语言环境设置为Locale.UK:

Android 7.0 has multi-locale support, allowing the user to set more than one default locale. So if I set the primary locale to Locale.UK:

然后在导航到WebView时,区域设置从ar-AE更改 到en-GB.

Then on navigating to the WebView, the locale changes from ar-AE to en-GB.

Android 7.0 API更改:

API更改列表中所述,与之相关的新方法语言环境中的语言已添加到API 24中的以下类中:

As indicated in the list of API changes, new methods pertaining to locale have been added to the following classes in API 24:

Locale:

Locale:

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