在写安卓应用的界面的时候,如果想把界面的TitleBar去掉,在Manifest里有两种方法:
1.如果想整个应用程序都没有TitleBar,则把Manifest文件里面的
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"修改为:android:theme="@android:style/Theme.NoTitleBar"或android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
2.如果只想某一个activity没有TitleBar,则在Manifest里面将该activity添加:
android:theme="@android:style/Theme.NoTitleBar"或android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
但当添加完该语句后,在手机端运行出错,具体的原因为:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
出错的原因:因为我们想要实现的主题(NoTitleBar)扩大了ActionBarActivity,所以需要使用Theme.AppCompat主题。
查看MainActivity.java的代码,发现我们创建的Activity是继承了ActionBarActivity!所以只需要将ActionBarActivity改为Activity,让我们的Activity继承Activity就可以了。