去掉android的屏幕上的title bar
去掉屏幕上的title bar有3个方法:
1. Java代码实现
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
setContentView(R.layout.main);
//...
}
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
setContentView(R.layout.main);
//...
}
但使用这种方法,用户体验不太好,在Activity将要显示时,仍然会出现title bar,然后再去掉的。
2. 自定义style配置文件
在\res\values里面的style.xml添加:
<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<stylename="NoTitle"parent="android:Theme">
<itemname="android:windowNoTitle">true</item>
</style>
</resources>
<resources>
<stylename="NoTitle"parent="android:Theme">
<itemname="android:windowNoTitle">true</item>
</style>
</resources>
然后在AndroidManifest.xml文件里,给需要去掉title bar的activity的节点上加上android:theme="@style/NoTitle,代码如下:
<activityandroid:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/NoTitle"/>
android:configChanges="orientation|keyboardHidden"
android:theme="@style/NoTitle"/>
3. 直接在AndroidManifest.xml中进行修改
原来我们可以无需自定义style配置的,直接调用系统的就行了:
<activityandroid:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar"/>
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar"/>
如果我们要设置整个Application都去掉title bar,那么就设置application:
<applicationandroid:icon="@drawable/lightbulb"android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
android:theme="@android:style/Theme.NoTitleBar">