You need to use a Theme.AppCompat theme (or descendant) with this activity
Posted 柳鲲鹏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了You need to use a Theme.AppCompat theme (or descendant) with this activity相关的知识,希望对你有一定的参考价值。
- 具体错误
2021-11-01 20:03:17.567 14095-14095/com.serenegiant.usbcameratest E/androidRuntime: FATAL EXCEPTION: main
Process: com.serenegiant.usbcameratest, PID: 14095
java.lang.RuntimeException: Unable to start activity ComponentInfocom.serenegiant.usbcameratest/com.serenegiant.usbcameratest.MainActivity: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3483)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3655)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2108)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7879)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:552)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.serenegiant.usbcameratest.MainActivity.onCreate(MainActivity.java:63)
- 解决办法一
由继承自AppCompatActivity改为继承自Activity
- 解决办法二
第一步:在Testz\\app\\build.gradle,添加绿色这两句
dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
exclude group: 'com.android.support', module: 'support-annotations'
)
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
testCompile 'junit:junit:4.12'
第二步:在我们需要的界面activity中添加,绿色部分
<activity android:name="com.chs.mt.gd_tosicke.main.MainActivity"
android:windowSoftInputMode="stateHidden|adjustPan"
android:theme="@style/AppThemeprice"
android:screenOrientation="portrait"
>
然后去style.xml添加
<style name="AppThemeprice" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
以上是关于You need to use a Theme.AppCompat theme (or descendant) with this activity的主要内容,如果未能解决你的问题,请参考以下文章
Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Context
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.