本地化Android应用程序,以便我可以在应用程序内切换区域设置

kat*_*tit 4 android localization

如何本地化应用程序,以便它使用特定的区域设置,而不管设备上设置的区域设置是什么?我想让用户可以设置他们选择的语言.

到目前为止,我在我的Application类中有这样的代码:

@Override
public void onCreate()
{
    //Set locale
    String l = Preferences.getLocale(getApplicationContext());
    if (!l.equals(""))
    {
        Locale locale = new Locale(l);
        Locale.setDefault(locale);
        Configuration config = getBaseContext().getResources().getConfiguration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(
            config, getBaseContext().getResources().getDisplayMetrics());
    }
    LogData.InsertMessage(getApplicationContext(), "Application started");
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,我似乎在set locale中显示得很好(TextViews)但是菜单标题和toasts将落入默认语言环境.

有没有1-2-3如何让它正常工作?我使用2.2版本

小智 5

这篇文章解释了如何在您的应用中强制本地化.