您的位置:首页 > 移动开发

Android Studio中报错 You need to use a Theme.AppCompat theme (or descendant) with this activity

2016-04-07 00:10 423 查看

1.错误描述:

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.best.keke.tabdemo01/com.best.xxxx.tabdemo01.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

2.原因:在AndroidManifest.xml文件中使用了

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">


在MainActivity 中我继承了 AppCompatActivity。这是因为AppCompatActivity是v7兼容包里面的。所以此处需要用到兼容包中的theme即可。

3.解决如下:

a.

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">


b.或者在MainActivity 中继承了Activity即可。

参考链接:1.http://stackoverflow.com/questions/26689279/java-lang-illegalstateexception-you-need-to-use-a-theme-appcompat-theme-or-des

2.http://stackoverflow.com/questions/18063395/actionbarcompat-java-lang-illegalstateexception-you-need-to-use-a-theme-appcom
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: