异常IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
2016-12-26 13:41
465 查看
在项目中遇到了这样一个问题,今天解决了,记录下来并且与大家共勉。。。
我先说我的需求,,
我要将欢迎也设置成全屏,并且没有标题栏、和状态栏,,然后我就出现了这个问题:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
设置标题栏时我给这个activity设置了主题,,
然后就出现了这个问题,最后找到了这个问题的所在。
解决:
从错误提示中提到Theme.AppCompat theme,这是因为我们的activity一定是继承了兼容包中的类,
比如我这里就无意中继承了ActionBarActivity,它来自android.support.v7.app.ActionBarActivity。
所以就要使用与其配合的AppCompat的theme才行。
1.根据提示来使用AppCompat的theme,如下:
[html] view
plain copy
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/9e12f1d3e499fc949c886e7c9e0484f9)
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:label="@string/app_name" >
不过我要设置全屏,但我并没有找到,所以虽然错误不见了,但并没有达到我的预期。
2.如果不是那么强烈需要继承自ActionBarActivity,就直接继承Activity吧。问题自然搞定!
我先说我的需求,,
我要将欢迎也设置成全屏,并且没有标题栏、和状态栏,,然后我就出现了这个问题:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
设置标题栏时我给这个activity设置了主题,,
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
然后就出现了这个问题,最后找到了这个问题的所在。
解决:
从错误提示中提到Theme.AppCompat theme,这是因为我们的activity一定是继承了兼容包中的类,
比如我这里就无意中继承了ActionBarActivity,它来自android.support.v7.app.ActionBarActivity。
所以就要使用与其配合的AppCompat的theme才行。
1.根据提示来使用AppCompat的theme,如下:
[html] view
plain copy
![](https://oscdn.geek-share.com/Uploads/Images/Content/201611/a7c8e286f463007e2a900848b93dd72c.png)
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:label="@string/app_name" >
不过我要设置全屏,但我并没有找到,所以虽然错误不见了,但并没有达到我的预期。
2.如果不是那么强烈需要继承自ActionBarActivity,就直接继承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解决方法
- 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.
- 关于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.
- 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
- java.lang.IllegalStateException: 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 解决办法