去掉屏幕上的title bar有3个方法:android
1. Java代码实现
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
//...
}
留意这语句所在的位置的,彷佛全部requestWindowFeature的操做都要放在setContentView的前面。
但使用这种方法,用户体验不太好,在Activity将要显示时,仍然会出现title bar,而后再去掉的。
2. 自定义style配置文件
在\res\values里面的style.xml添加:
<?
xml
version
="1.0"
encoding
="utf-8"
?>
<
resources
>
<
style
name
="NoTitle"
parent
="android:Theme"
>
<
item
name
="android:windowNoTitle"
>true
</
item
>
</
style
>
</
resources
>
这里的代码应该看明白了吧!
而后在AndroidManifest.xml文件里,给须要去掉title bar的activity的节点上加上android:theme="@style/NoTitle,代码以下:
<
activity
android:name
=".MainActivity"
android:configChanges
="orientation|keyboardHidden"
android:theme
="@style/NoTitle"
/>
3. 直接在AndroidManifest.xml中进行修改
原来咱们能够无需自定义style配置的,直接调用系统的就好了:
<
activity
android:name
=".MainActivity"
android:configChanges
="orientation|keyboardHidden"
android:theme
="@android:style/Theme.NoTitleBar"
/>
若是咱们要设置整个Application都去掉title bar,那么就设置application:
<
application
android:icon
="@drawable/lightbulb"
android:label
="@string/app_name"
android:theme
="@android:style/Theme.NoTitleBar"
>