第一种方法:
在Activity的onCreate()中,在 setContentView()之前调用方法:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //设置全屏
setContentView();
第二种方法:
在AndroidManifest.xml清单文件中,找到相应的Activity节点;
<activity android:name=".MainActivity"
android:theme="@android:style/Theme.NoTitleBar" /> ---- 去掉标题栏
或者:
<activity android:name=".SharedElementsAnimaton"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" /> ---- 设置全屏
第三种方法:
以上两种方法都是针对单个的Activity,如果要使整个应用都没有标题栏,可以如下设置:
在AndroidManifest.xml清单文件中,找到相应的application节点;
<application
...
android:theme="@android:style/Theme.NoTitleBar" ---- 去掉标题栏
... >
application/>
或者:
<application
...
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" ---- 设置全屏
... >
application/>
但是 ,某一天当我在一个程序中使用第二种方法时却导致程序在启动时崩溃了,是的,程序崩掉了。。。。把代码再回退到android:theme="@style/AppTheme"就没问题了,于是我就查一下,原来,在android:theme="@style/XXXX"还有其他的五种主题也可以取消标题栏:
android:theme="@style/Theme.Design.NoActionBar"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:theme="@style/Theme.Design.Light.NoActionBar"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
当我使用了android:theme="@style/Theme.Design.Light.NoActionBar"之后程序不会崩溃,而且是以没有标题栏(也没有actionBar)的样式显示。
至于这几种主题之间的区别现在还不是很理解,可以作为下一个知识点,学习之后再详细记录一下。