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

后端 未结 3 379
说谎
说谎 2021-01-18 02:48

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

相关标签:
3条回答
  • 2021-01-18 03:19

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

    0 讨论(0)
  • 2021-01-18 03:23

    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

    0 讨论(0)
  • 2021-01-18 03:34

    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;
    }
    
    0 讨论(0)
提交回复
热议问题