Android: Is there a way to change the default language for Android to a new language?

I am trying to find out if it is possible to change the default language of the Android OS to another. For which the language, for example, is not specified in the settings: how to programmatically configure the device language.

+5
source share
3 answers

Use this to change the language programmatically -

Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);

Enter the country code instead of "en_US" in any language you want ... for example, for japanese - "ja_JP" For Arabic - "ar" or check this link for the country code -

http://code.google.com/apis/igoogle/docs/i18n.html

And create a folder in res / values-ja for japanese or res / values-ar for arabic.

string.xml , . , , -ar .., ...

res/values-ar -

<?xml version="1.0" encoding="UTF-8"?>
  <resources>
    <string name="spinner_label">تصفية حسب</string>
    <string name="app_name">2011 فرق</string> 
    <string name="search">بحث :</string>
</resource>

, .

+13

, , .

:

public static void changeLocale(Locale locale) {
    try {
        Class<?> activityManagerNative = Class.forName("android.app.ActivityManagerNative");

        Object am = activityManagerNative.getMethod("getDefault").invoke(activityManagerNative);

        Object config = am.getClass().getMethod("getConfiguration").invoke(am);
        config.getClass().getDeclaredField("locale").set(config, locale);
        config.getClass().getDeclaredField("userSetLocale").setBoolean(config, true);

        am.getClass().getMethod("updateConfiguration", android.content.res.Configuration.class).invoke(am, config);
        Log.i(LOG_TAG, "send change locale request");
    } catch (Exception e) {
        Log.e(LOG_TAG, "change locale error:", e);
    }
}
+3

. github

0
source

All Articles