在选项卡中显示首选项活动

时间:2012-03-05 14:56:29

标签: android tabs preferenceactivity

我有三个标签。我在前两个标签中添加了功能。现在,我希望使用第三个选项卡显示设置/首选项,以便用户可以从各种设置列表中进行选择。我希望使用Preference Activity来做同样的事情。有可能这样做吗?如果有,怎么样?如果不是,我可以使用的替代选项是什么?

3 个答案:

答案 0 :(得分:2)

要将标签的内容设置为Avtivity,您需要创建一个明确的Intent并将其传递给TabHost.TabSpec.setContent(Intent intent)方法。

这样的事情应该有用......

// This code assumes tabHost is a reference to your TabHost widget
// and that you have created the tag and indicator variables

TabHost.TabSpec spec;
Intent intent;

intent = new Intent(this, MyPreferenceActivity.class);
spec = tabHost.newTabSpec(tag).setIndicator(indicator).setContent(intent);
tabHost.addTab(spec);

答案 1 :(得分:1)

考虑这个解决方案:

基于片段创建TabHost,即每个选项卡显示一个片段。然后对其中一个标签使用PreferenceFragment。

答案 2 :(得分:0)

我找到了解决方案。正如MisterSquonk所述,我添加了一个偏好活动作为设置选项卡的意图。然后,我在活动中创建了一个动态首选项布局。应该尝试片段方法 - 谢谢Stefan和MisterSquonk !!