更改区域设置,但保持从左到右和其他电话方向

时间:2016-05-09 16:17:54

标签: android localization locale translation

我有一个以两种语言提供的应用程序 - 英语和希伯来语。

我使用Translation Editor添加了希伯来字符串,我根据用户选择更改了区域设置。

更改区域设置时,它会像我想要的那样将字符串设置为希伯来语,但它也会将工具栏方向更改为从右向左的希伯来语并带来标题和右边的后退按钮。

英语区域设置(默认):

enter image description here

希伯来语区域设置: enter image description here

有没有办法让工具栏方向像英文一样? 我想保留工具栏左侧的后退按钮标题

android:layoutDirection="ltr"android:supportsRtl="false"添加到toolbar xml后

修改。箭头向后。怎么解决它?

enter image description here

3 个答案:

答案 0 :(得分:11)

  

更改区域设置,但保持从左到右和其他手机方向

具体而言,将android:supportsRtl="false"添加到清单文件中的<application>元素。

了解更多信息Link

答案 1 :(得分:5)

添加android:layoutDirection =&#34; ltr&#34;到你的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;
}