Android 去掉title bar的3个方法

来源:互联网 发布:如何保存淘宝视频 编辑:程序博客网 时间:2024/06/05 16:11

原文地址:http://daisy-sea.iteye.com/blog/1180659


1. Java代码实现 

<span style="font-family:Courier New;">public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);            requestWindowFeature(Window.FEATURE_NO_TITLE);             setContentView(R.layout.main);          //...  } </span>

留意这语句所在的位置的,似乎所有requestWindowFeature的操作都要放在setContentView的前面。 
但使用这种方法,用户体验不太好,在Activity将要显示时,仍然会出现title bar,然后再去掉的。 


2. 自定义style配置文件 
在\res\values里面的style.xml添加: 

<span style="font-family:Courier New;"><?xml version="1.0" encoding="utf-8"?>  <resources>          <style name="NoTitle" parent="android:Theme">                  <item name="android:windowNoTitle">true</item>          </style>  </resources>  </span>

然后在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: 

<span style="font-family:Courier New;"><application android:icon="@drawable/lightbulb" android:label="@string/app_name"                      android:theme="@android:style/Theme.NoTitleBar">  </span>


0 0
原创粉丝点击