How to right align PreferencesActivity in android?

前端 未结 14 2205
一向
一向 2020-12-31 07:07

I have PreferencesActivity which I need it to be right aligned because I want to use Arabic language, I tried to use android:layout_gravity=\"right\"

14条回答
  •  一生所求
    2020-12-31 07:34

    After checking for a few solutions i came upon something that might help. It's not elegant and works only on 4 and up but it's better than nothing...

    add this code to onResume()

        Locale locale = new Locale("iw");// Hebrew in this case
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,
              getBaseContext().getResources().getDisplayMetrics());
    

    Of course you can choose to change the locale in your preference activities onResume() method only in your MainActivity's onResume() change locale back to your preferred (or user defined) locale.

    Hope this helps!

提交回复
热议问题