在进行android开发时,每个Activity会默认带上一个title bar用以显示程序名,有时为了扩大屏幕的显示区域需要去掉这个titlebar,去掉屏幕上的title bar有3个方法,
第一个方法是在代码去掉title bar
在Activity的onCreate中加入如下代码:
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
但是使用这种方法,是在Activity将要显示的时候,仍然会出现title bar,然后再将其去掉,用户体验不好。
第二种方法是使用style配置文件
步骤如下:
1.在res/values文件夹下创建一个xml文件,名为mainStyle.xml,内容如下:
- <?xml version="1.0"encoding="utf-8"?>
- <resources>
- <style name="NoTitle"parent="android:Theme">
- <itemnameitemname="android:windowNoTitle">true</item>
- </style>
- </resources>
- <?xml version="1.0"encoding="utf-8"?>
- <resources>
- <style name="NoTitle"parent="android:Theme">
- <itemnameitemname="android:windowNoTitle">true</item>
- </style>
- </resources>
2.然后在AndroidManifest.xml中需要去掉title bar的activities的节点上加上一个样式属性
- <activity android:name=".view.AutoTaskDemo" android:label="@string/app_name"android:configChanges="keyboardHidden|orientation|locale" android:theme="@style/NoTitle">
- <activity android:name=".view.AutoTaskDemo" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|locale" android:theme="@style/NoTitle">
第三种方法是直接在AndroidManifest.xml中进行修改
把需要去掉title bar的activities的节点上加上一个样式属性,代码如下:
- <activity android:name=".view.SettingActivity"android:configChanges="keyboardHidden|orientation"android:theme="@android:style/Theme.NoTitleBar"/>
- <activity android:name=".view.SettingActivity" android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.NoTitleBar"/>
也可以在AndroidManifest.xml文件的application节点上修改,对所有的activity都有效,代码如下:
- <application android:icon="@drawable/icon" android:label="@string/app_name"android:theme="@android:style/Theme.NoTitleBar">