将标头添加到PreferenceActivity

Pea*_*nut 11 android

所以我发现Android PreferenceScreen对样式不是很友好.在显示首选项之前,是否有一种简单的方法可以在首选项屏幕上添加标题(例如图像)?我目前正在扩展PreferenceActivity类,但是有人可以告诉我如何在标题中添加线性布局吗?

谢谢

Mir*_*tor 26

在我的应用程序中,我完全按照您的要求执行此操作:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    setContentView(R.layout.preferences_layout);
}
Run Code Online (Sandbox Code Playgroud)

并在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>
Run Code Online (Sandbox Code Playgroud)

注意xml中的android:id设置ListView现在您可以控制首选项屏幕的布局,并且只要使用内置首选项,就可以使用首选项的默认样式.

  • 哦,我刚从你的评论中注意到你已经很难修复它.嗯......也许其他人正在寻找解决方案 (2认同)