在preferenceAcivity设置自定义标题栏 [英] Set custom title bar in PreferenceAcivity

查看:123
本文介绍了在preferenceAcivity设置自定义标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用preferenceActivity,我怎么可以设置自定义标题栏?不仅文本,但背景颜色,大小 - 整个布局

I am using PreferenceActivity, how can I set a custom title bar? Not only text but background color, size - the whole layout.

推荐答案

preferenceActivity扩展ListActivity ,当你夸大从XML preferences与添加preferencesFromResource(),它把东西到标准的ListView ListActivity 使用。

PreferenceActivity extends ListActivity, and when you inflate the preferences from xml with addPreferencesFromResource(), it puts the stuff into the standard ListView that ListActivity uses.

因此​​,基本上,你可以使用的setContentView()来指定一个布局,但是你需要有一个的ListView 在它与ID @ +安卓ID /列表。

So basically, you can use setContentView() to specify a layout, but you need to have a ListView in it with the id "@+android:id/list".

因此​​,使用kleini的例子code:

So using kleini's example code:

protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.login_settings);
    setContentView(R.layout.login_settings_layout);
}

您需要在 login_settings_layout.xml 一个ListView看起来是这样的:

You would need a ListView in login_settings_layout.xml that looks something like:

<ListView 
    android:id="@+android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    /> 

这篇关于在preferenceAcivity设置自定义标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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