Android issue: You need to use a Theme.AppCompat theme (or descendant) with this activity

报这个错一看就是要你使用:Theme.AppCompat theme

前提要有v7包:com.android.support:appcompat-v7
当然v4最好也有:com.android.support:support-v4

Activity可以直接使用<application/>定义的theme;也可以在<activity/>中加入 android:theme="…" 来指定主题。

比较坑的是,最近接手一个老项目,没用Theme.AppCompat;然后我用了v7, 使用了AppCompatActivity,结果就报这错了。

这里坑我的是:明明说使用这个Theme.AppCompat或其派生的子theme就可以;结果多一个层次的继承还是报错,如:

<!-- base theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar" />

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme" />

如上,在使用时,用@style/AppTheme,就照样报错了(测试机小米2s,5.0系统)…

不得不去掉base theme:

<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" />

猜你喜欢

转载自blog.csdn.net/jjwwmlp456/article/details/77230013