Android 7.0及更高版本的多语言支持不起作用

时间:2017-07-13 12:00:12

标签: android

从Android 7.0开始,对多语言用户的Android语言和语言环境支持得到了改进。

https://developer.android.com/guide/topics/resources/multilingual-support.html

但它并不完全符合我的想法。

这是res / layout / activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.tistory.httphckim999.languageprioritytest.MainActivity"
    android:orientation="vertical">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/first_test" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/second_test" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/third_test" />
</LinearLayout>

这是res / values / strings.xml

<resources>
    <string name="app_name">Language Priority Test</string>
    <string name="first_test">first default</string>
    <string name="second_test">second default</string>
    <string name="third_test">third default</string>
</resources>

这是res / values-ko / strings.xml

<resources>
    <string name="first_test">first ko</string>
</resources>

这是res / values-zh / strings.xml

<resources>
    <string name="second_test">second zh</string>
</resources>

这是res / values-ja / strings.xml

<resources>
    <string name="third_test">third ja</string>
</resources>

我的测试设备区域设置优先级为&#34; ko&gt; zh&gt; JA&#34;

我认为它应该是这样印刷的。

第一个

second zh

第三次

但它是这样打印的

第一个

第二次默认

第三次默认

我无法理解为什么会这样打印。

我在这里上传我的测试项目。

https://github.com/kimhc999/LanguagePriorityTest

我在Galaxy S7(7.0),PIXEL(8.0预览版3)和模拟器(7.0,7.1,8.0)中进行了测试。但是所有这些都有相同的结果。

任何人都可以帮助我吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

它以预期的方式工作,你以错误的方式感知它。在您的应用程序中,默认语言为英语,您将所有值放在strings.xml中,如下所示

<resources>
    <string name="app_name">Language Priority Test</string>
    <string name="first_test">first default</string>
    <string name="second_test">second default</string>
    <string name="third_test">third default</string>
</resources>

手机语言为 ko ,您只为该

设置了1个值

这是res / values-ko / strings.xml

<resources>
    <string name="first_test">first ko</string>
</resources>

当您运行应用程序时,它将首先在 values-ko 文件夹中搜索值,如果值不可用,那么将从values / strings.xml中选择默认值,即在你的情况下英语。

由于只有first_test在values-ko中可用,因此对于second_test和third_test,它将从默认值文件夹中选择值,并且您得到了正确的结果:

第一个

第二次默认

第三次默认

相关问题