更改设备语言后,TextView显示不在strings.xml中的字符串 [英] TextView showing strings that are not in the strings.xml when device language is changed

查看:151
本文介绍了更改设备语言后,TextView显示不在strings.xml中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改设备语言时,strings.xml中没有的字符串会显示在我的文本视图中.

When I change the device language, strings that are not in the strings.xml are showing in my text view.

下面是我的文本查看代码:

Below is my text view code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:paddingTop="@dimen/padding_all_activity_16"
    android:text="@string/check_document_image_readable"
    android:textSize="18sp"
    android:textStyle="bold" />
......

在values/string.xml文件中:

in the values/string.xml file:

    <string name="check_document_image_readable">A foto ficou legível?</string>

我的应用程序不支持其他语言(它是葡萄牙语).

My app don't support other languages (it is written in portuguese).

当我在将设备设置为英语的情况下运行应用程序时:

When I run the app withe the device set to English:

但是,如果我更改为西班牙语(即使我杀死了该应用程序):

But if I change to Spanish (even if I kill the App):

我正在使用Android Studio 3.0.1开发.这种情况发生在API的24和25中.

I'm developing with Android Studio 3.0.1. This happens in the API's 24 and 25.

如何仅将value/strings.xml用于任何设备语言?

How can I use only the values/strings.xml for any device language?

推荐答案

Android支持根据设备的语言设置,使用不同的语言和文化.您可以使用希望支持的语言的不同字符串资源来实现该功能.

Android has support to Different Languages and Culturesaccording to the device's language setup. You can achieve that working with different strings resource for which language that you desire to support.

在您的项目中,右键单击res/values/,然后选择New-> Values资源文件.输入字符串"作为文件名,并将source选项设置为main.在可用的限定词"中,单击">>"按钮,将区域设置"移至选择的限定词"部分.选择您要支持的语言,然后选择区域(默认为:任何区域),然后单击确定". Android Studio将自动生成一个新的资源文件,也称为"strings.xml".

In your project, right-click res/values/ and select New -> Values resource file. Enter "strings" for the file name and leave the source option set to main. In the Available qualifiers and click ">>" button to move "Locale"to the Chosen qualifiers section. Select the language that you wish to support and select the region (default is: Any region) and left-click "Ok". Android studio will automatically generate a new resource file also called "strings.xml".

我为什么要提到那个? Android在运行时会寻找默认的字符串资源.可能发生的情况是您没有使用默认的字符串资源,而是使用了"string-pt"资源,如果您没有用于西班牙语或其他语言的资源字符串文件,那么这将是一个问题.

Why did I mention that? Android at run time looks for a default string resource. What might be happening is that you're not using a default string resource, instead you're using a 'string-pt' resource, this would be a problem if you don't have resource string file for Spanish or other language.

这篇关于更改设备语言后,TextView显示不在strings.xml中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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