简体   繁体   中英

Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat.Light.DarkActionBar'

I'm following the android development tutorials from developers.android.com, and currently I'm trying to style my action bar using the information given here: https://developer.android.com/training/basics/actionbar/styling.html#CustomBackground7

Here's the code of res/values/themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>

    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@android:style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_background</item>
        <!-- Support library compatibility -->
        <item name="background">@drawable/actionbar_background</item>

    </style>
</resources>

I see red cross icons beside the "style" opening tags, hovering on which the error message reads: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat.Light.DarkActionBar'.

  • My application has minSdkVersion="11" and targetSdkVersion="21", I tried changing the minSdkVersion to 13, 14 but it made no difference
  • Someone suggested to check whether appcompat has been marked as library project or not, I checked it and the "isLibrary" option was checked in the appcompat properties window.
  • I also made sure that appcompat was added to my project as a library project.
  • removing "@android" from "@android:style" or removing the "@" doesn't work. However in the first style tag, when I remove "@android" then the red cross sign goes away, but that doesn't happen for the second style tag.

Please help. I've been at it since morning and I'm not getting anywhere.

Try to delete android: , like this:

<style name="CustomActionBarTheme"
       parent="@style/Theme.AppCompat.Light.DarkActionBar">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM