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"
for PreferenceScreen
but it didn't work.
This is my XML:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="right">
<PreferenceCategory android:title="General Settings">
<CheckBoxPreference
android:title="Full Screen"
android:defaultValue="false"
android:summary="Always view as Full Screen"
android:key="fullScreenPref" />
<Preference
android:title="Report Bugs"
android:summary="Notify us for any Bugs or Errors"
android:key="bugs"/>
<Preference
android:title="About"
android:summary="Version 1.0.0"
android:key="about"/>
</PreferenceCategory>
</PreferenceScreen>
This is how I use the XML inside PreferencesActivity
:
addPreferencesFromResource(R.layout.preferences);
same as my problem and this is the solution:
inside your PreferenceFragment:
the result is like this image:right to left Preference
After spending some time searching about our shared question, I found nothing useful. obviosly android api doesn't support RTL prefefrences. it means no support for persian/hebrew/arabic languages. But afterall I tried to find some way to right align an editText. I drived EditTextPreference class and implemented onCreateView method again. here is my code:
the rest of the preferences in the standard android api should be the same(btw I haven't tried yet). maybe someday we should fully implement rtl support in android preferences and host it on github. Hope this code snippet helps you.
Alright, this might be quite late, but anyways if you are targeting Android 3.0 or higher, you should use PreferenceFragment with can be somehow made RTL.
So you should create a fragment in your code like this:
now you should create an Activity that adds this fragment to its layout. You can create a layout for your activity and put the fragment in it via xml element or using the
FragmentManager
class. But the key to make the preferences Right-To-Left is to put a layout_direction="rtl" attribute in the layout file for a parent element of the fragment. i.e.Notice the
android:layoutDirection="rtl"
on theRelativeLayout
element that fixes the problem.Now add the Activity Java code like any other activity and add to your manifest file.
Hope it's not too late :)
for preferences fragment you can make its container to have this attribute
You could do that by using a custom layout with calling
setLayoutResource(int layoutResId)
.res/layout/preference_layout.xml: (Note that this is based on HoloEverywhere library org.holoeverywhere.preference.Preference)
In your custom Preference: