Skip to content Skip to sidebar Skip to footer

Changing Locale But Keep Left-to-right And Other Phone Orientations

I have an app that is available in two languages - English and Hebrew. I added Hebrew strings using the Translation Editor and I am changing the Locale according to the user select

Solution 1:

Change Locale but keep left-to-right and other phone orientations

Specifically, add android:supportsRtl="false" to the <application> element in your manifest file.

For more information Link

Solution 2:

Add android:layoutDirection="ltr" to your appbar layout. That will force ltr in any layout direction

Solution 3:

I had this problem too. I had a method to change the locale of the language and the application configuration :

private String loadPreference() {
    SharedPreferencesshp= getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
    Stringlanguage= shp.getString("Language","fa");
    LocalemyLocale=newLocale(language);
    Locale.setDefault(myLocale);
    Configurationconfig=newConfiguration();
    config.locale = myLocale;
    getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    Stringlocale= getResources().getConfiguration().locale.getDisplayName();
    System.out.println(locale);
    return locale;
}

It is changing locale and simultaneously changing the layoutDirection, so you can solve this by setting the direction manually:

private String loadPreference() {
    SharedPreferencesshp= getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
    Stringlanguage= shp.getString("Language","fa");
    LocalemyLocale=newLocale(language);

    Configurationconfig=newConfiguration();
    config.setLocale(myLocale);
    //manually set layout direction to a LTR location
    config.setLayoutDirection(newLocale("en"));
    getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    Stringlocale= getResources().getConfiguration().locale.getDisplayName();

    return locale;
}

Post a Comment for "Changing Locale But Keep Left-to-right And Other Phone Orientations"