Android Studio中报错 You need to use a Theme.AppCompat theme (or descendant) with this activity
16lz
2021-01-23
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
更多相关文章
- android使用sharedPreferences()方法读写文件操作
- apktool高版本产生compileSdkVersion等错误
- 在系统里设置文件默认打开APP
- Android 使用OKHttp3请求接口401,返回Authorization Required错误
- Android Studio构建时报gradle相关错误的解决办法
- 第一次执行Cordova build android失败原因一则
- android studio 打包出现的错误
- Android实现屏幕截图并保存截图到指定文件