![](/img/trans.png)
[英]Issue with You need to use a Theme.AppCompat theme (or descendant) with this activity Theme.AppCompat theme (or descendant) with this activity"
[英]Error: You need to use a Theme.AppCompat theme (or descendant) with this activity
我在执行时(在Android监视器控制台上)收到此错误:
06-16 11:25:38.227 1555-1555/com.example.mysampleapp E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mysampleapp/com.example.mysampleapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
我正在尝试使用此项目将zxing集成到我的应用程序中,并在此处进行说明。 我的清单是这样的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mysampleapp">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="android.support.multidex.MultiDexApplication"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="randomkeywhichyoudontneedtoknow" />
</activity>
<activity
android:name=".SplashActivity"
android:label="mysampleapp"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"></activity>
</application>
</manifest>
Styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
(需要在问题中添加一些文本,因此可以满足stackoverflow!)
尝试删除此行:
android:theme="@style/AppTheme.NoActionBar"
从您的Activity
。
当样式文件包含时,您的AppTheme
已在使用Theme.AppCompat.Light.NoActionBar
,并且清单已在整个应用程序中应用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.