我们写程序的时候经常要全屏显示或者不显示标题。比如我们做地图导航的时候就不要标题了,下面介绍三种方法来实现Android去掉标题。
第一种:也一般入门的时候经常使用的一种方法
在setContentView()方法的前面插入代码:
1
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
//去掉标题栏
|
第二种:在AndroidManifest.xml文件中定义
去掉整个应用的标题栏:
1
2
3
4
5
|
<
application
android:icon
=
"@drawable/icon"
android:label
=
"@string/app_name"
android:theme
=
"@android:style/Theme.NoTitleBar"
>
|
不过有时候不需要去掉整个程序的应用,只想去掉一个的时候就在Activity中。
第三种:在res/values目录下面新建一个style.xml的文件
这种方法是有经验的开发者最喜欢的方法,因为它把功能分开的;对于后期的维护非常方便。
个人建议用第三种方法:
styleAndroidManifest.xml
1
2
3
4
5
6
7
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
resources
>
<
style
name
=
"concealTitle"
>
<
item
name
=
"android:windowNoTitle"
>true</
item
>
</
style
>
</
resources
>
|
定义完了一个style,接下来就是在AndroidManifest.xml中使用了:
1
2
3
4
5
|
<
application
android:icon
=
"@drawable/icon"
android:label
=
"@string/app_name"
android:theme
=
"@style/concealTitle"
>
|