我的應用程序無法在模擬器中運行。引用的錯誤是 java.lang.IllegalStateException:您需要在此活動中使用 Theme.AppCompat 主題(或后代)。我讀過許多類似的問題,包括: .IllegalStateException: You need to use a Theme.AppCompat 主題(或后代)與此活動ActionBarCompat:java.lang.IllegalStateException:您需要使用 Theme.AppCompat但這些都沒有奏效。res>values>styles.xml 文件中的代碼是:<resources> <style name = "AppBaseTheme" parent = "TextAppearance.AppCompat"> <item name = "android:colorPrimary">@android:color/holo_blue_bright</item> <item name = "android:colorPrimaryDark">@android:color/holo_blue_dark</item> <item name = "android:colorAccent">@android:color/holo_red_dark</item> </style></resources>src>main>AndroidManifest.xml 文件中的代碼為:<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.hbpm1"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppBaseTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>如果有人能提供幫助,我將非常感激:)
1 回答

皈依舞
TA貢獻1851條經驗 獲得超3個贊
應用程序主題不能<style name = "AppBaseTheme" parent = "TextAppearance.AppCompat">
,因為TextAppearance
主題根本不能用于應用程序主題。因此,請使用任何Theme.AppCompat
作為應用程序的默認主題。為此,我可以舉一個例子:
<style name = "AppBaseTheme" parent = "Theme.AppCompat">
或者
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
ETC。
希望它能起作用
添加回答
舉報
0/150
提交
取消