第一种:也一般入门的时候经常使用的一种方法
?
requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
注意这句一定要写在setContentView()方法的前面,不然会报错的
或者
- ??@Override??
- ????public?void?onCreate(Bundle?savedInstanceState)?{??
- ????????super.onCreate(savedInstanceState);??
- ????????setContentView(R.layout.main);??
- ??????
- ????????ActionBar?actionBar?=?getActionBar();??
- ???????
- ????????actionBar.hide();??
- //actionBar.show();??? }?
第二种:在AndroidManifest.xml文件中定义
?
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
?
可以看出,这样写的话,整个应用都会去掉标题栏,如果只想去掉某一个Activity的标题栏的话,可以把这个属性加到activity标签里面
?
第三种:这种在一般的应用中不常用,就是在res/values目录下面新建一个style.xml的文件
?
例如:
?
?
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="notitle">
<item name="android:windowNoTitle">true</item>
</style>?
</resources>
<resources>
<style name="notitle">
<item name="android:windowNoTitle">true</item>
</style>?
</resources>
?
这样,我们就自定义了一个style,就相当于一个主题,然后在AndroidManifest.xml文件中定义
?
?
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/notitle">
android:label="@string/app_name"
android:theme="@style/notitle">
?
这样也可以达到去掉标题栏的效果
?
三种去掉标题栏方法的总结
?
第一种,有的时候我们会看到,会先出现标题栏,然后再消失,因为我们只是在activity的oncreate方法中定义的,第二种相对第一种比较好一些,不会出现这种情况,第三种我个人感觉最好,这样把功能分开,便于维护和扩展
?
再介绍全屏的方法:
?
第一种
?
?
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
?
第二种
?
?
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
?
第三种
?
application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/fullscreem"
android:label="@string/app_name"
android:theme="@style/fullscreem"