您的位置:首页 > 产品设计 > UI/UE

添加RequestWindowFeature去除标题崩溃

2016-04-15 22:59 447 查看
mark:

在更换了Android Studio 2.0 作为开发安卓的IDE后,在创建Activity时发现时默认的继承类变成了ActionBarActivity ,
当按照传统做法在程序中加上requestWindowFeature(Window.FEATURE_NO_TITLE);想去除标题栏
然而程序却崩溃了,在搜索之后找到了解决方案。做此笔记备忘!


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

ActionBar actionBar=getSupportActionBar();

actionBar.hide();

也可以简写成一句话代码:

getSupportActionBar().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" 平板风格显示


转自:http://www.cnblogs.com/stuart/p/4463305.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: