如何强制在android应用语言 [英] how to force language in android application

查看:135
本文介绍了如何强制在android应用语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
  更改应用程序本身的语言环境

在我的应用程序需要力的语言让我们说,我有语言环境中英语作为默认的波兰和芬兰,根据的 我创造功能也贴波纹管那个帖子,函数被调用createActivity(),但问题是它没有工作....任何想法,为什么?有什么建议?

 私人无效的setLocale(字符串区域code){
        区域设置区域设置=新区域(区域code);
        Locale.setDefault(区域);
        配置配置=新配置();
        config.locale =区域;
        。getBaseContext()getResources()updateConfiguration(。配置,getBaseContext()getResources()getDisplayMetrics());
    }
 

解决方案

下面是我得到了这么远。我知道这个问题是解决了,但我的解决办法是更简单,更紧凑。不需要其他的变化,没有一款Android:configurationChanges在你的清单属性的所有活动

 公共类SigmaMiddleEastApplication扩展PPGApplication {

    @覆盖
    公共无效onConfigurationChanged(配置NEWCONFIG){
        newConfig.locale = Locale.ENGLISH;
        super.onConfigurationChanged(NEWCONFIG);

        Locale.setDefault(newConfig.locale);
        。getBaseContext()getResources()updateConfiguration(NEWCONFIG,getResources()getDisplayMetrics());
    }
}
 

当心这可能会导致问题: <一href="http://stackoverflow.com/questions/12503125/what-could-cause-an-android-activity-to-relaunch-itself-infinitely-when-returnin">What可能会导致Android的活动从相机返回时重新启动本身无限?

Possible Duplicate:
Changing Locale within the app itself

in my application I need to "force" language let's say that I have locale in english as default polish and finnish, according to that post I had created function posted also bellow, function is called in createActivity(), but the problem is it does not work.... any idea why? Any suggestions?

private void setLocale(String localeCode){
        Locale locale = new Locale(localeCode);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    }

解决方案

Here is what I got so far. I know this question is resolved, but my solution is easier and more compact. No other changes are needed, no android:configurationChanges attribute for all activities in your manifest.

public class SigmaMiddleEastApplication extends PPGApplication {

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        newConfig.locale = Locale.ENGLISH;
        super.onConfigurationChanged(newConfig);

        Locale.setDefault(newConfig.locale);
        getBaseContext().getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics());
    }
}

BEWARE this may cause problems: What could cause an Android activity to relaunch itself infinitely when returning from camera?

这篇关于如何强制在android应用语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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