在android中去掉标题栏有三种方法,它们也有各自的特点。
1.在代码里实现
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
原创部分:但是这种方法如果Activity是继承自appcompatactivity的话,这种方法不仅没有效果还有时候还会报错和闪退,这时候要用
- this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
记住:这句代码要写在setContentView()前面。
2.在清单文件(manifest.xml)里面实现
- <application android:icon="@drawable/icon"
- android:label="@string/app_name"
- android:theme="@android:style/Theme.NoTitleBar">
3.在style.xml文件里定义
- <?xml version="1.0" encoding="UTF-8" ?>
- <resources>
- <style name="notitle">
- <item name="android:windowNoTitle">true</item>
- </style>
- </resources>
- <application android:icon="@drawable/icon"
- android:label="@string/app_name"
- android:theme="@style/notitle">
其实可以看得出来,第二种方法和第三种方法实质是一样的,只不过第二种方法调用的是系统定义好的style.xml文件,而第三种方法则是在自己的应用里定义style.xml,然后再自己再调用,其实道理是一样的,第三种方法做起来更有成就感。
转载自 博主:liuzhidong123
地址:http://blog.csdn.net/liuzhidong123/article/details/7818531