关于“you need to use a theme.appcompat theme (or descendant) with this activity”错误
2014-09-23 12:59
423 查看
在写安卓应用的界面的时候,如果想把界面的TitleBar去掉,在Manifest里有两种方法:
1.如果想整个应用程序都没有TitleBar,则把Manifest文件里面的
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"
但当添加完该语句后,在手机端运行出错,具体的原因为:
出错的原因:因为我们想要实现的主题(NoTitleBar)扩大了ActionBarActivity,所以需要使用Theme.AppCompat主题。
查看MainActivity.java的代码,发现我们创建的Activity是继承了ActionBarActivity!所以只需要将ActionBarActivity改为Activity,让我们的Activity继承Activity就可以了。
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"
但当添加完该语句后,在手机端运行出错,具体的原因为:
[code]java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity[/code]
出错的原因:因为我们想要实现的主题(NoTitleBar)扩大了ActionBarActivity,所以需要使用Theme.AppCompat主题。
查看MainActivity.java的代码,发现我们创建的Activity是继承了ActionBarActivity!所以只需要将ActionBarActivity改为Activity,让我们的Activity继承Activity就可以了。
相关文章推荐
- 解决错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android错误之:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 关于You need to use a Theme.AppCompat theme (or descendant) with this activity的问题
- 我的Android进阶之旅------>解决错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 【已解决】You need to use a Theme.AppCompat theme (or descendant) with this activity
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android开发~you need to use a theme.appcompat theme (or descendant) with this activity
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- 使用ActionBar,调整Theme时遇到You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- Android Studio You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity
- java.lang.IllegalStateException: You need to use a theme.appcompat theme (or descendant) with this activity