【问题标题】:set my app to thai language将我的应用程序设置为泰语
【发布时间】:2016-12-17 21:22:17
【问题描述】:

我希望将我的应用程序设置为使用 value-th\string.xml(我拥有泰语中的所有字符串值)。这就是我要做的。 -应用程序启动。检查 sharepreference 值语言(在这种情况下为英语/泰语)如果是泰语,我将运行泰语。我有这个功能,但是,我注意到在语言环境中,我没有泰语选项。

public static void updateLanguageResources(Context context, String language) {
        Locale locale = new Locale(language);
        Locale.setDefault(locale);

        Resources resources = context.getResources();

        android.content.res.Configuration configuration = resources.getConfiguration();
        configuration.locale = locale;

        resources.updateConfiguration(configuration, resources.getDisplayMetrics());



    }

我还尝试使用以下代码通过设置进行更改。但是,这会将电话设置更改为泰语,我的意图是更改仅适用于我的应用程序。不是设备的设置。

Intent intent = new Intent(Settings.ACTION_LOCALE_SETTINGS);
            startActivity(intent);

欢迎提出任何建议。提前致谢。

【问题讨论】:

  • 试试这个演示:androidhive.info/2014/07/…
  • @Damini 这就是 Intent intent = new Intent(Settings.ACTION_LOCALE_SETTINGS);开始活动(意图);做。我可以将设备语言更改为泰语,但这会影响手机中的所有应用程序。我只想在我自己的应用程序中使用泰语。
  • 找到了这个[链接]stackoverflow.com/questions/2264874/…让我先试试
  • hm.. 我想我遇到了同样的问题 Locale 没有泰语选项。
  • 找到了答案。谢谢。

标签: android locale


【解决方案1】:

我找到了自己问题的答案。希望这可以在将来对其他人有所帮助。

首先需要准备一个values\string.xml(默认英文),第二个语言values-th\string.xml

public static void changeLocale(Context context, Locale locale) {
        Configuration conf = context.getResources().getConfiguration();
        conf.locale = locale;
        Locale.setDefault(locale);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            conf.setLayoutDirection(conf.locale);
        }

        System.out.println("changeLocale");
        context.getResources().updateConfiguration(conf, context.getResources().getDisplayMetrics());
    }

然后调用函数...确保泰语文件是-th

Utils.changeLocale(MyApplication.getInstance(), new Locale("th"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多