How to programmatically suppress specific locale i

2019-02-16 01:48发布

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?

1条回答
成全新的幸福
2楼-- · 2019-02-16 02:06

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....

查看更多
登录 后发表回答