将ActionBar添加到PreferenceActivity [英] Add ActionBar to a PreferenceActivity
问题描述
我正在尝试使用 PreferenceActivity $ c来制作
设置
活动
$ C>。问题是无论我做什么, ActionBar
都不会出现。
I am trying to make a Settings
Activity
using a PreferenceActivity
. The problem is that the ActionBar
won't show up no matter what I do.
我试过 getSupportActionBar
, getActionBar
, setActionBar
。什么都行不通。
我看到其他应用设置 ActionBar
s。他们不使用 PreferenceActivity
?
I've tried getSupportActionBar
, getActionBar
, setActionBar
. Nothing works.
I see other apps settings with ActionBar
s. Do they not use PreferenceActivity
?
推荐答案
如果您使用的是AppCompat主题,你必须注意一些观点。
If you are using an AppCompat theme, you have to pay attention to some points.
PreferenceActivity
不会扩展 AppCompatActivity
或已弃用的 ActionBarActivity
。
作为解决方案,您可以创建 PreferenceFragment
,并在标准 AppCompatActivity
使用 >。当然你也可以使用工具栏
。
As solution you can create a PreferenceFragment
as you are doing and use it in a standard AppCompatActivity
. Of course you can use also a Toolbar
.
此外,使用新的22.1+ appcompat你可以使用 AppCompatDelegate 将AppCompat的支持扩展到任何活动。
Moreover with the new 22.1+ appcompat you can use the AppCompatDelegate to extend AppCompat's support to any Activity.
您可以查看 AppCompatPreferenceActivity ,您可以在其中找到此技术的示例。
You can check this official link to AppCompatPreferenceActivity, where you can find an example of this technique.
这篇关于将ActionBar添加到PreferenceActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!