0

我有一个 android 应用程序作为设备的 UI 工作。我的意思是,当我打开设备时,我没有看到默认的 android 界面,而是看到了我的应用程序。当我更改 Android 语言时,android 的 os 字符串会更改,但我的应用程序字符串不会。它需要重新启动。重新启动后它会改变,但这不是我想要的。因为,该应用程序是我的主应用程序,我必须重新启动所有系统才能重新启动应用程序。如您所见,此应用程序适用于所有系统生命周期。所以我需要它,在它运行时更改它的语言,而无需重新启动。

我怎样才能做到这一点?

请注意:语言环境不适用于我想要的东西。

4

2 回答 2

1

在您的onCreate方法中调用以下命令以选择语言环境字符串中提供的语言。

/**
 * Set the default Locale for app
 * @param context context on which the locale will be implemented
 * @param locale new locale for example, <b>sv</b> for Swedish or <b>en</b> for English
 */
public static void setDefaultLocale(Context context, String locale) {
    Locale locJa = new Locale(locale.trim());
    Locale.setDefault(locJa);

    Configuration config = new Configuration();
    config.locale = locJa;

    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());

    locJa = null;
    config = null;
}
于 2012-04-13T06:32:41.407 回答
1

您可以使用此功能更改语言..

  public void changeLang(String lang) {
    if (lang.equalsIgnoreCase(""))
        return;


    String languageToLoad  =lang; // your language
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    DebugLog.d("Selectedlang"+lang);


}
于 2017-02-20T11:33:53.103 回答