使用ActionBar,调整Theme时遇到You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
2015-04-06 10:19
841 查看
今天在写一个ActionBar时,想把标题颜色改成白色,以匹配app的风格,默认是黑色的:
![](http://img.blog.csdn.net/20150406100956822?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3lwMzMxMjAz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
这种黑色的标题栏,原因是因为清单文件AndroidManifest.xml中,默认配置的风格是:android:theme="@style/AppTheme"
于是我开始尝试更换这个主题;最开始找了几个类似于@android:style/Theme.Light的系统自带的Light模式的主题,但是运行起来发现都会报异常:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
原因是,为了兼容性,我没有使用系统的ActionBar,而是使用的兼容性包V7包中的actionbar:android.support.v7.app.ActionBar,于是导致无法匹配一般Android系统的主题,提示我们需要使用Theme.AppCompat主题或者其子类主题,经过一番查找,发现如下几个主题是可用的:
@style/Theme.AppCompat ,@style/Theme.AppCompat.Light,@style/Theme.AppCompat.Light.DarkActionBar
其中,在使用了@style/Theme.AppCompat.Light之后,达到了想要的效果,问题解决:
这种黑色的标题栏,原因是因为清单文件AndroidManifest.xml中,默认配置的风格是:android:theme="@style/AppTheme"
于是我开始尝试更换这个主题;最开始找了几个类似于@android:style/Theme.Light的系统自带的Light模式的主题,但是运行起来发现都会报异常:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
原因是,为了兼容性,我没有使用系统的ActionBar,而是使用的兼容性包V7包中的actionbar:android.support.v7.app.ActionBar,于是导致无法匹配一般Android系统的主题,提示我们需要使用Theme.AppCompat主题或者其子类主题,经过一番查找,发现如下几个主题是可用的:
@style/Theme.AppCompat ,@style/Theme.AppCompat.Light,@style/Theme.AppCompat.Light.DarkActionBar
其中,在使用了@style/Theme.AppCompat.Light之后,达到了想要的效果,问题解决:
相关文章推荐
- 关闭 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解决方法
- 使用AlertDialog报错 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解决方法
- 【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解决方法
- 使用AlertDialog报错 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解决在清单文件里消除Bar报错:You need to use a 原来Theme.AppCompat theme (or descendant) with this activity.