我们怎样才能隐藏标题栏,在使用操作栏? [英] How Can we hide title bar while using action bar?

查看:143
本文介绍了我们怎样才能隐藏标题栏,在使用操作栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ActionBarSherlock,我试图隐藏我的应用程序的标题栏,但每当我这样做,我得到一个 NullPointerException异常访问<$ C时, $ C>动作条如何删除/隐藏标题栏?请注意,我不是指操作栏的标题。我指的是上面的操作栏标题栏。我是一个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);
 

解决方案

发现在这一个解决方案。如果你声明你的主题上的Andr​​oidManifest.xml ,标题栏会自行消失。虽然,我不知道为什么只对的Andr​​oidManifest.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. :)

这篇关于我们怎样才能隐藏标题栏,在使用操作栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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