[英]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.