我有一个以两种语言提供的应用程序 - 英语和希伯来语。
我使用Translation Editor添加了希伯来字符串,我根据用户选择更改了区域设置。
更改区域设置时,它会像我想要的那样将字符串设置为希伯来语,但它也会将工具栏方向更改为从右向左的希伯来语并带来标题和右边的后退按钮。
英语区域设置(默认):
有没有办法让工具栏方向像英文一样? 我想保留工具栏左侧的后退按钮和标题。
将android:layoutDirection="ltr"
或android:supportsRtl="false"
添加到toolbar
xml后修改。箭头向后。怎么解决它?
答案 0 :(得分:11)
答案 1 :(得分:5)
添加android:layoutDirection =" ltr"到你的appbar布局。这将迫使ltr在任何布局方向
答案 2 :(得分:3)
我也有这个问题。我有一个方法来更改语言的语言环境和应用程序配置:
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;
}
它正在更改区域设置并同时更改layoutDirection,因此您可以通过手动设置方向来解决此问题:
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;
}