添加一个标题为preferenceActivity [英] Adding a header to a PreferenceActivity

查看:101
本文介绍了添加一个标题为preferenceActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我发现,Android的preferenceScreen不是很气派友好。有只是一个头(比如图像)添加到preferencescreen的preferences显示前一个半简单的方法?我目前延长preferenceActivity类,但可能有人告诉我如何加入到头部的线性布局?

So I have found that android PreferenceScreen is not very style-friendly. Is there a semi-simple way to just add a header (say an image) to the preferencescreen before the preferences are shown? I am currently extending the PreferenceActivity class, but could someone show me how to add a linear layout to the header?

感谢

推荐答案

在我的应用程序,你的要求我做的正是这样的:

In my app I do exactly what you are requesting like this:

@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>

注意机器人:ID 的ListView 在XML设置 现在,你可以控制在preferences屏幕的布局,并使用为preferences默认的风格,只要你使用内置的preferences。

Notice the android:id set on the ListView in the xml Now you have control over the layout of the preferences screen and use the default style for the preferences as long as you use built-in preferences.

这篇关于添加一个标题为preferenceActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆