Change Default Phone Language By Changing Application Language In Android?
Is there any way to change language of phone by changing the language from application. I mean when I change the language of my application then the default phone language will als
Solution 1:
Localelocale=newLocale("en_US");
Locale.setDefault(locale);
Configurationconfig=newConfiguration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);
then
And make a folder in res/values-ja for japanese or res/values-ar for arabic..
And make string.xml file And put the languages whatever you want on your layout
Its example of res/values-ar for arabic--
<?xml version="1.0" encoding="UTF-8"?><resources><stringname="spinner_label">حسب</string><stringname="app_name">فرق</string><stringname="search">بحث:</string></resource>
Solution 2:
I dont know that it can be changed programatically, but after you changed your app language you can ask user to change device language also,
Ask user to change device language
Intentintent=newIntent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.LanguageSettings");
startActivity(intent);
Change app language
<activity
android:name=".ui.SomeActivity"android:configChanges="locale"
:
:
</activity>
publicstaticvoidsetLanguage(Context context, String languageToLoad) {
Log.d(TAG, "setting language");
Locale locale = newLocale(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");
}
Solution 3:
add android:configChanges="locale" to your activity decalaration in AndroidManifect file.
Then call following method from onCreate of that activity .
publicstaticvoidsetLanguage(Context context, String languageToLoad) {
Log.d(TAG, "setting language");
Localelocale=newLocale(languageToLoad); //e.g "sv"LocalesystemLocale= SystemLocale.getInstance().getCurrentLocale(context);
if (systemLocale != null && systemLocale.equals(locale)) {
Log.d(TAG, "Already correct language set");
return;
}
Locale.setDefault(locale);
android.content.res.Configurationconfig=newandroid.content.res.Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,context.getResources().getDisplayMetrics());
Log.d(TAG, "Language set");
}
Post a Comment for "Change Default Phone Language By Changing Application Language In Android?"