编程Android中更改语言 [英] Change language programatically in Android

查看:170
本文介绍了编程Android中更改语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能改变一个应用程序的编程语言,同时还采用了Android资源?

Is it possible to change the language of an app programmatically while still using Android resources?

如果没有,是否可以请求资源在特定的语言?

If not, is it possible to request a resource in an specific language?

我想,让用户从应用程序更改应用程序的语言。

I would like to let the user change the language of the app from the app.

推荐答案

这是可能的。您可以设置语言环境。不过,我不会建议。我们已经尝试过在早期阶段,它的基本战斗系统。我们有用于改变语言相同的要求,但决定定居的事实,用户界面​​应当是相同的手机的用户界面。它是通过设置本地化工作,但太马车。而你要你从我的经验,进入活动(每次活动)每次设置。这里是一个code,如果你还需要这(再次,我不建议)

It's possible. You can set the locale. However, i would not recommend that. We've tried it at early stages, it's basically fighting the system. We have same requirement for changing language, but decided to settle to the fact that UI should be same as phone UI. It was working via setting locale but was too buggy. And you have to set it every time you enter activity ( each activity ) from my experience. here is a code if you still need this ( again, i don't recommend that )

    Resources res = context.getResources();
    // Change locale settings in the app.
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = new Locale(language_code.toLowerCase());
    res.updateConfiguration(conf, dm);

如果您有语言上的具体内容 - 你可以更改设置,基础

If you have language specific content - you can change that base on the setting.

这篇关于编程Android中更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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