首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

Android Manifest 報錯:找不到 @style/AppTheme 解決方案

     編輯:程式設計綜合問答

錯誤訊息

error: Error: No resource found that matches the given name (at 'theme' with value '@style/AppTheme').

原因分析

AndroidManifest.xml 中 <application android:theme="@style/AppTheme"> 引用了 AppTheme 樣式,但專案 res/values/styles.xml 裡並未定義該樣式,導致編譯失敗。

解決步驟

1. 建立/編輯 res/values/styles.xml

<resources xmlns:android="https://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="android:Theme.Light">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowContentOverlay">@android:color/transparent</item>
    </style>
</resources>

2. 依需求調整父樣式

  • Theme.Material.Light(API 21+)
  • Theme.AppCompat.Light.NoActionBar(使用 AppCompat 時)

3. 同步 Manifest

確認 android:theme="@style/AppTheme" 拼寫完全一致,重建專案即可。

進階技巧

  • 針對不同 API 等級,可在 values-v21/styles.xml 覆寫 Material 樣式。
  • 使用 tools:replace="android:theme" 解決 Library 衝突。

補上缺失的 AppTheme 定義,錯誤即刻消失。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved