所以我发现android PreferenceScreen 不是很友好。是否有一种半简单的方法可以在显示首选项之前将标题(比如图像)添加到首选项屏幕?我目前正在扩展 PreferenceActivity 类,但有人可以告诉我如何向标题添加线性布局吗?
谢谢
最佳答案
在我的应用程序中,我完全按照您的要求进行操作:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
setContentView(R.layout.preferences_layout);
}
在 preferences_layout.xml
文件中:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ImageView
android:id="@+id/myCustomImageView"
android:src="@drawable/xmas"
android:layout_width="fill_parent"
android:layout_height="50dp"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/myCustomImageView"
/>
</RelativeLayout>
注意在xml中ListView
设置的android:id
现在,您可以控制首选项屏幕的布局,只要您使用内置首选项,就可以使用首选项的默认样式。
关于android - 向 PreferenceActivity 添加 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5443491/