【问题标题】:Change android app language when Phone language is changed from Settings从设置更改电话语言时更改 android 应用程序语言
【发布时间】:2015-06-19 15:19:07
【问题描述】:

当设置中的语言发生更改时,我想更改我的应用字符串语言。

就像,现在是英语。 当我从设置中切换到印地语时,我的 android 应用程序中的文本也应该是印地语。

怎么做?

【问题讨论】:

    标签: android android-studio localization


    【解决方案1】:
    1. 创建values-xx,其中“xx”是任何语言代码,如“en”、“fr”、“sp”、“ar” ....等等

    2. 在同一个文件夹中创建一个名为string.xml的xml。

    3. 在该 xml 中创建字符串

      <string name="welcome">write in the language which you put as the language code</string

    【讨论】:

      【解决方案2】:

      您应该在这个网站上: http://developer.android.com/guide/topics/resources/localization.html

      您必须在 res 文件夹中创建 values 文件夹以进行本地化。并且您必须在 values 文件夹中创建 string.xml。例如:

      土耳其语的values-tr

      values-fr 表示法语

      【讨论】:

        【解决方案3】:

        values-hi/strings.xml

        <string name="welcome">स्वागतम</string>
        <string name="email">ईमेल पता</string>
        <string name="password">पासवर्ड</string>
        <string name="login">लॉगिन</string>
        <string name="signup">खाता नहीं है? साइन अप करें</string>
        

        【讨论】:

          【解决方案4】:

          使用

          Locale.getDefault().getLanguage();
          

          为您的设备获取设备语言。(例如)

          然后进行切换以在您的应用程序中的“字符串”值之间进行交换。(values/string.xml)

          参考: Get the current language in device

          引用:

          Locale.getDefault().getLanguage()       ---> en      
          Locale.getDefault().getISO3Language()   ---> eng 
          Locale.getDefault().getCountry()        ---> US 
          Locale.getDefault().getISO3Country()    ---> USA 
          Locale.getDefault().getDisplayCountry() ---> United States 
          Locale.getDefault().getDisplayName()    ---> English (United States) 
          Locale.getDefault().toString()          ---> en_US
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-05-09
            • 1970-01-01
            • 2015-10-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多