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):
Hebrew Locale:
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?
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.
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.
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.
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.
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.
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.
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
Add android:layoutDirection="ltr" to your appbar layout. That will force ltr in any layout direction
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With