Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 selection.

When changing the Locale, it sets the strings to Hebrew like I wanted, but its also changes the toolbar orientation to right-to-left for Hebrew and brings the title and back-button to the right.

English Locale (Default):

enter image description here

Hebrew Locale: enter image description here

Is there a way to keep the toolbar orientation like the English one? I want to keep the back button and the title in the left of the toolbar.

Edit: after adding either android:layoutDirection="ltr" or android:supportsRtl="false" to the toolbar xml. arrow is backwards. how ti fix it?

enter image description here

like image 385
Ofek Agmon Avatar asked May 09 '16 16:05

Ofek Agmon


People also ask

What is locale default Android?

The default locale is appropriate for tasks that involve presenting data to the user. In this case, you want to use the user's date/time formats, number formats, rules for conversion to lowercase, and so on. In this case, it's safe to use the convenience methods.

How do I change my locale application?

Go to app > res > values > right-click > New > Value Resource File and name it as strings. Now, we have to choose qualifiers as Locale from the available list and select the language as Hindi from the drop-down list. Below is the picture of the steps to be performed. Now, In this resource file string.

How can I change the default locale on my Device?

If you want to change locale settings on your device, the Set Locale and Language app 1 might prove helpful as well. Locale-Einstellung looks almost the same. MoreLocale 2 2 might offer an alternative, as it also allows to create custom locales -- which is also supported by Custom Locale 3.

How do I change the orientation of my Android phone?

Android: Your phone's default layout caters to the right-handed user. If you're left-handed, switch your layout to right-to-left with just a tap to be more comfortable using your device. First you need to get into your developer options, then you can enable the layout change. Here's how: Go into Settings > About Phone.

How do I enable the right to left layout on Android?

Enable Android's Secret Right-to-Left Layout If You're Left Handed. Android: Your phone's default layout caters to the right-handed user. If you're left-handed, switch your layout to right-to-left with just a tap to be more comfortable using your device. First you need to get into your developer options, then you can enable the layout change.

Why does the activity flag prevent orientation changes in Android?

This altogether prevents orientation changes from happening while the user is in the Activity with the flag set. So if you rotate your device the screen won’t rotate with it.


Video Answer


3 Answers

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

like image 101
Emre Aktürk Avatar answered Jan 27 '23 13:01

Emre Aktürk


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

like image 31
daxgirl Avatar answered Jan 27 '23 11:01

daxgirl


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

private String loadPreference() {
    SharedPreferences shp = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
    String language = shp.getString("Language","fa");
    Locale myLocale = new Locale(language);
    Locale.setDefault(myLocale);
    Configuration config = new Configuration();
    config.locale = myLocale;
    getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    String locale = 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() {
    SharedPreferences shp = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
    String language = shp.getString("Language","fa");
    Locale myLocale = new Locale(language);

    Configuration config = new Configuration();
    config.setLocale(myLocale);
    //manually set layout direction to a LTR location
    config.setLayoutDirection(new Locale("en"));
    getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    String locale = getResources().getConfiguration().locale.getDisplayName();

    return locale;
}
like image 36
Pegah Kiaei Avatar answered Jan 27 '23 13:01

Pegah Kiaei