我有 PreferencesActivity
我需要它右对齐因为我想使用阿拉伯语,我尝试使用 android:layout_gravity="right"
为 PreferenceScreen
但它不起作用。
这是我的 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>
这就是我在 PreferencesActivity
中使用 XML 的方式:
addPreferencesFromResource(R.layout.preferences);
最佳答案
在花了一些时间搜索我们的共同问题后,我没有找到任何有用的东西。显然 android api 不支持 RTL 首选项。这意味着不支持波斯语/希伯来语/阿拉伯语。但毕竟我试图找到一些方法来右对齐 editText。我驱动了 EditTextPreference 类并再次实现了 onCreateView 方法。 这是我的代码:
/**
* Created by omid on 1/12/14.
*/
public class RtlTextPreference extends EditTextPreference {
public RtlTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View onCreateView(ViewGroup parent) {
View view = super.onCreateView(parent);
RelativeLayout layout = (RelativeLayout) ((LinearLayout) view).getChildAt(1);
layout.setGravity(Gravity.RIGHT);
return view;
}
}
标准 android api 中的其余首选项应该是相同的(顺便说一句,我还没有尝试过)。 也许有一天我们应该在 android 首选项中完全实现 rtl 支持并将其托管在 github 上。 希望这段代码对您有所帮助。
关于java - 如何在android中右对齐PreferenceActivity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11332340/