簡體   English   中英

Theme.AppCompat.Light.DarkActionBar - 找不到資源

[英]Theme.AppCompat.Light.DarkActionBar - No resource found

如何正確使用Android支持庫,因為我的清單文件中有此錯誤:

android:theme="@style/Theme.AppCompat.Light.DarkActionBar"

error: Error: No resource found that matches the given name 
(at 'theme' with value '@style/Theme.AppCompat.Light.DarkActionBar').
AndroidManifest.xml /ttab   line 39 Android AAPT Problem

我的朋友之前在其他計算機上為我實現了此功能,現在我必須單獨執行此操作。 請幫我:)

我正在使用ADT

我的styles.xml:

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <style name="Theme.AppCompat.Light">
     <!-- theme customizations here. -->
    </style>


    <style name="Theme.AppCompat.Light.DarkActionBar" parent="Theme.AppCompat.Light">
      <!-- theme customizations here. -->
    </style>


</resources>

在“android-support-v7-appcompat”項目中:

  • 從Package explorer中刪除“android-support-v7-appcompat”。
  • 再次導入並選中“復制到工作區”
  • 在屬性 - > Android - >在項目構建目標中,取消選中Android 2.2並檢查Android 4.1.2
  • 在Java構建路徑中,取消選中是否有任何.jar庫,並取消選中Dependences

另一方面,使用“android-support-v7-appcompat”的項目:

  • 在屬性 - > Android中添加庫,但取消選中“IsLibrary”。
  • 在Android - > Project build tarjet中檢查Android 4.0。
  • 在“Java Build Path” - > Order and Export - >取消選中.jar庫
  • 最后做一個“項目 - >清理”兩個項目

如果您使用的是Gradle,則說明最新版本的兼容性庫存在問題。

如果build.gradle文件中包含以下內容, build.gradle末尾帶有'+'

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

然后它可能會抓住你想要的更高版本的庫。

將依賴項更改為:

dependencies {
    compile 'com.android.support:appcompat-v7:18.0+'
}

可以解決你的問題。

你能試試嗎?

android:theme="Theme.AppCompat.Light.DarkActionBar"

代替

android:theme="@style/Theme.AppCompat.Light.DarkActionBar"

在您的應用程序依賴項文件中檢查您是否具有依賴項

compile 'com.android.support:appcompatv[anything here]

要么

implement 'com.android.support:appcompat[anything here]

刪除或注釋掉它們,單擊“燈泡”以獲取自動建議,然后選擇添加庫依賴項。 單擊appcompat的autofillbulb

滾動第一個appcompat版本的選項。 該庫將添加到依賴項列表下方。 重建應用程序或使緩存無效並重新啟動

在一種情況下,這沒有用,並且轉到包含項目的文件夾,刪除.gradle文件並重新啟動Android Studio已經有效。 來自Sneh Pandya在https://reformatcode.com/code/android/error-while-gradle-sync中的回答

  1. 轉到項目目錄(或項目視圖)
  2. 找到並打開.idea目錄
  3. 刪除緩存和庫目錄< - 這是必不可少的
  4. 使高速緩存/重新啟動無效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM