【问题标题】:How can I show title in PreferenceActivity如何在 PreferenceActivity 中显示标题
【发布时间】:2012-11-06 07:02:28
【问题描述】:

我使用PreferenceActivity 以及在此示例中的平板电脑Android from 4.0

但是在header中不显示标题,怎么会有这些广告呢?

【问题讨论】:

标签: android preferences


【解决方案1】:

PreferenceActivity 扩展了 ListActivity,当您使用 addPreferencesFromResource() 从 xml 扩展首选项时,它会将这些内容放入 ListActivity 使用的标准 ListView 中。所以基本上,你可以使用 setContentView() 来指定一个布局,但你需要有一个 ID 为“@+android:id/list”的 ListView。

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:

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

【讨论】:

  • addPreferencesFromResource(...) 已弃用
  • 从资源文件加载您的首选项。在此处查看示例代码:linkPreferenceActivity
【解决方案2】:

这是因为 ttitle 未启用。

getActionBar().setDisplayShowTitleEnabled(false);

改成然后调用setTitle()

getActionBar().setDisplayShowTitleEnabled(true);
setTitle("Your Title");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多