我使用ActionBarSherlock,我试图隐藏我的应用程序的标题栏,但每当我这样做,我得到一个 NullPointerException异常
访问动作条如何删除/隐藏标题栏?请注意,我不是指操作栏的标题。我指的是上面的操作栏标题栏。我是一个Android 2.3的设备上运行我的应用程序。
下面是我的code:(我的类扩展 SherlockFragmentActivity
)
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_Sherlock);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
动作条动作条= getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //我在这里得到了NullPointerException异常。
// ...
的setContentView(R.layout.tab_navigation);
解决方案
发现在这一个解决方案。如果你声明你的主题上的AndroidManifest.xml
,标题栏会自行消失。虽然,我不知道为什么只对的AndroidManifest.xml
宣布时,工作不是code。
的原因NullPointerException异常是动作条
的代名词到了 TitleBar中
更高版本(ICS及更新版本) 。通过使用兼容性库和 ActionBarSherlock
,隐藏 TitleBar中
也将意味着隐藏动作条
。
下面是如何设置应用程序使用Sherlock的主题:(你应该在应用程序的标签添加)
安卓主题=@风格/ Theme.Sherlock
如果你知道如何隐藏code中的标题栏,请随意修改我的答案,包括你的答案。如果任何人都可以解释为什么它只能在清单文件,而不是在code。如果是好的。 :)
I'm using ActionBarSherlock and I'm trying to hide the title bar of my application but whenever I do that, I get a NullPointerException
when accessing the ActionBar
How do I remove/hide the title bar? Please note that I'm not referring to the title of the action bar. I'm referring to the title bar above the action bar. I'm running my application on an Android 2.3 device.
Below is my code: (My class extends SherlockFragmentActivity
.)
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_Sherlock);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
ActionBar actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //I get the NullPointerException here.
//...
setContentView(R.layout.tab_navigation);
解决方案
Found the solution on this one. If you declare your theme on AndroidManifest.xml
, the title bar will go away on its own. Although, I don't why it only works when declared on AndroidManifest.xml
and not on code.
The reason for the NullPointerException is that ActionBar
is synonymous to the TitleBar
on higher versions (ICS and newer). By using the compatibility library and ActionBarSherlock
, hiding the TitleBar
will also mean hiding the ActionBar
.
Below is how you can set your application to use Sherlock's theme: (You should add it on the application's tag)
android:theme="@style/Theme.Sherlock"
If you know how to hide the title bar on code, please feel free to modify my answer to include your answer. And if anyone can explain why it only works on the manifest file and not on code if would be nice. :)