How to right align PreferencesActivity in android?

2019-02-06 09:24发布

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);

13条回答
相关推荐>>
2楼-- · 2019-02-06 10:07

In my point of view this can be the solution: Set each view's LayoutDirection to rtl;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);

view.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

return view;}
查看更多
登录 后发表回答