如何在Android应用程序中以编程方式压制特定的区域设置[英] How to programmatically suppress specific locale in Android application

本文是小编为大家收集整理的关于如何在Android应用程序中以编程方式压制特定的区域设置的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我们知道,对于支持不同地区的支持,Android应用程序至少是可以自定义的.就我而言,我的应用程序目前支持6个地区,一切正常.每当用户选择电话语言环境时,应用程序都会切换到另一个语言环境,并且所有菜单都以本地语言为单位.

现在的问题是我希望在应用程序中抑制特定的语言环境,因为我将使用不同的渠道,定价策略等在不同国家/地区分发应用程序(并非总是通过Android市场).因此,如果要说中国的应用程序 - 用户无法将语言环境切换到英语或法语.

最简单的方法就是从应用程序中删除其他语言环境资源 - 我知道这一点.但是从源维护点起,这不是很舒适,因此我更喜欢有一些程序化方法来降低/抑制应用程序中的某些地区.

有什么想法?

推荐答案

使用此代码...

    private void callSwitchLang(String langCode) {
    Locale locale = new Locale(langCode);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics()); 
onCreate(null);
}

在那个mothods中,你传递了您所选的语言代码..

本文地址:https://www.itbaoku.cn/post/102674.html

问题描述

All we know that Android application is highely customizable with respect to support of different locales. In my case my application currently supports 6 locales and everything works smooth. Whenever user selects phone locale, application switches to another locale and all menus, messages are in local languages.

Now question is in my desire to programmatically suppress specific locale(s) in application, since I'm going to distribute application in different countries using different channels, pricing policies and so on (not always through Android Market). So if application is intended for let say China - user couldn't switch locale to English or French.

Most simple way is just remove other locale resources from application - I understand that. But from point of source maintenance it's not very comfortable, so I would prefer to have some programmatic way for declining/suppressing of some locales in application.

Any ideas?

推荐答案

Use this code...

    private void callSwitchLang(String langCode) {
    Locale locale = new Locale(langCode);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics()); 
onCreate(null);
}

In that mothods u pass your selected language code....