Android中去掉标题栏

Android中去掉标题栏有三种方法,它们也有各自的特点。

1.在代码里实现

  1. this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏  

记住:这句代码要写在setContentView()前面。

2.在清单文件(manifest.xml)里面实现

<application android:icon="@drawable/icon"   
        android:label="@string/app_name"   
        android:theme="@android:style/Theme.NoTitleBar"> 

这样用可以将整个应用设置成无标题栏,如果只需要在一个Activity设置成一个无标题栏的形式,只要把上面的第三行代码写到某一个Activity里面就可以了。

3.在style.xml文件里定义

1 <?xml version="1.0" encoding="UTF-8" ?>  
2 <resources>  
3     <style name="notitle">  
4         <item name="android:windowNoTitle">true</item>  
5     </style>   
6 </resources>  

然后面manifest.xml中引用就可以了,这种方法稍麻烦了些。

<application android:icon="@drawable/icon"   
        android:label="@string/app_name"   
        android:theme="@style/notitle">  

如果出现错误:

错误描述为:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

那么可能是该activtiy继承了ActionBarActivity;改成直接继承Activity即可;

转载自:http://blog.csdn.net/liuzhidong123/article/details/7818531

原文地址:https://www.cnblogs.com/kingsam/p/5609968.html