去掉标题栏/ActionBar后点击menu键时应用崩溃

 MainActivity 继承了 ActionBarActivity后,想要去掉标题栏(ActionBar),在程序中加上requestWindowFeature(Window.FEATURE_NO_TITLE);,结果标题栏是去掉了,但是在点击Menu键时应用会崩溃。在网上找了一下解决方法,都是把MainActivity继承ActionBarActivity改为继承Activity,这样虽然能够解决问题,但是如果一定是要继承ActionBarActivity不能改的话要怎么办呢?例如在我的程序里,需要调用getSupportFragmentManager(),如果MainActivity继承Activity的话我就没办法调用此函数。

 

解决办法:去掉requestWindowFeature(Window.FEATURE_NO_TITLE);这一句,改为下面两句:

ActionBar actionBar=getSupportActionBar();
actionBar.hide();

 

 

 

附:Android系统自带样式

在xml文件中进行配置

在项目的清单文件AndroidManifest.xml中,找到需要全屏或设置成无标题栏的Activity,在该Activity进行如下配置即可。

android:theme="@android:style/Theme.Dialog" 将一个Activity显示为能话框模式 
android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏 
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏 
android:theme="Theme.Light" 背景为白色 
android:theme="Theme.Light.NoTitleBar" 白色背景并无标题栏 
android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏 
android:theme="Theme.Black" 背景黑色 
android:theme="Theme.Black.NoTitleBar" 黑色背景并无标题栏 
android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏 
android:theme="Theme.Wallpaper" 用系统桌面为应用程序背景 
android:theme="Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏 
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏 
android:theme="Translucent"  透明背景
android:theme="Theme.Translucent.NoTitleBar"  透明背景并无标题
android:theme="Theme.Translucent.NoTitleBar.Fullscreen"  透明背景并无标题,全屏
android:theme="Theme.Panel"   面板风格显示
android:theme="Theme.Light.Panel" 平板风格显示

posted @ 2015-04-28 16:12  Stuart001  阅读(656)  评论(0编辑  收藏  举报