有没有办法通过从应用程序更改语言来更改电话语言。
我的意思是,当我更改应用程序的语言时,默认的电话语言也会更改。
对此有什么想法,请在这里分享。
提前谢谢。
我不知道
它可以通过编程方式更改,但是在您更改应用程序语言后,您也可以要求用户更改设备语言,
要求用户更改设备语言
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.LanguageSettings");
startActivity(intent);
更改应用语言
<activity
android:name=".ui.SomeActivity"
android:configChanges="locale"
:
:
</activity>
public static void setLanguage(Context context, String languageToLoad) {
Log.d(TAG, "setting language");
Locale locale = new Locale(languageToLoad); //e.g "sv"
Locale systemLocale = SystemLocale.getInstance().getCurrentLocale(context);
if (systemLocale != null && systemLocale.equals(locale)) {
Log.d(TAG, "Already correct language set");
return;
}
Locale.setDefault(locale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
Log.d(TAG, "Language set");
}
将android:configChanges="locale"添加到AndroidManifect文件中的活动贴花中。
然后从 on创建该活动 调用以下方法。
public static void setLanguage(Context context, String languageToLoad) {
Log.d(TAG, "setting language");
Locale locale = new Locale(languageToLoad); //e.g "sv"
Locale systemLocale = SystemLocale.getInstance().getCurrentLocale(context);
if (systemLocale != null && systemLocale.equals(locale)) {
Log.d(TAG, "Already correct language set");
return;
}
Locale.setDefault(locale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,context.getResources().getDisplayMetrics());
Log.d(TAG, "Language set");
}