Java Android : 有什么办法可以将 android 的默认语言更改为新语言吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9679574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:04:19  来源:igfitidea点击:

Android : Is there any way to change the default language of android to new language?

javaandroid

提问by Pattabi Raman

I'm trying to know whether it is possible to change the default android OS language to other. For which the language is not in the settings for instance: how to set the device 's language to burmese programmatically.

我想知道是否可以将默认的 android 操作系统语言更改为其他语言。对于语言不在设置中的情况,例如:如何以编程方式将设备的语言设置为缅甸语。

采纳答案by Hulk

Use this to change the language by programmatically--

使用它以编程方式更改语言 -

Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);

Write the countrycode of language in place of "en_US" whatever language you want...like for japanese--"ja_JP" For Arabic--"ar" or check this link for code of country--

写下语言的国家/地区代码代替“en_US”任何您想要的语言......就像日语一样--“ja_JP”对于阿拉伯语--“ar”或检查此链接以获取国家/地区代码--

http://code.google.com/apis/igoogle/docs/i18n.html

http://code.google.com/apis/igoogle/docs/i18n.html

And make a folder in res/values-jafor japanese or res/values-arfor arabic..

并在res/values-ja 中为日语创建一个文件夹,或在res/values-ar 中为阿拉伯语创建一个文件夹。

And make string.xml fileAnd put the languages whatever you want on your layout.. It will fetch the default language from values folder otherwise you want it manually then it will fetch from your external folder values-ar etc. like...

并制作string.xml 文件并将任何你想要的语言放在你的布局上..它会从 values 文件夹中获取默认语言,否则你需要手动它然后它会从你的外部文件夹 values-ar 等中获取,比如......

Its example of res/values-ar for arabic--

的阿拉伯语 res/values-ar示例——

<?xml version="1.0" encoding="UTF-8"?>
  <resources>
    <string name="spinner_label">????? ???</string>
    <string name="app_name">2011 ???</string> 
    <string name="search">??? :</string>
</resource>

Hope It will help you..

希望它会帮助你..

回答by idiottiger

you can change the locale to whatever you want and the system need support it.

您可以将区域设置更改为您想要的任何区域,并且系统需要支持它。

try this:

尝试这个:

public static void changeLocale(Locale locale) {
    try {
        Class<?> activityManagerNative = Class.forName("android.app.ActivityManagerNative");

        Object am = activityManagerNative.getMethod("getDefault").invoke(activityManagerNative);

        Object config = am.getClass().getMethod("getConfiguration").invoke(am);
        config.getClass().getDeclaredField("locale").set(config, locale);
        config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true);

        am.getClass().getMethod("updateConfiguration", android.content.res.Configuration.class).invoke(am, config);
        Log.i(LOG_TAG, "send change locale request");
    } catch (Exception e) {
        Log.e(LOG_TAG, "change locale error:", e);
    }
}

回答by Faisal Naseer

You can try this Localization Library. from github

你可以试试这个本地化库。来自 github