5

Ich lerne Material Design, insbesondere möchte ich meine App mit Material Design auch für die älteren Android-Versionen anpassen. Ich lese diese Anleitung: https://developer.android.com/training/material/compatibility.html#SupportLibFehler: Fehler: Keine Ressource gefunden, die den angegebenen Namen entspricht: attr 'colorAccent'

Über Farbpalette, der Guide sagt:

To obtain material design styles and customize the color palette with the Android v7 Support Library, apply one of the Theme.AppCompat themes:

<!-- extend one of the Theme.AppCompat themes --> 
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light"> 
    <!-- customize the color palette --> 
    <item name="colorPrimary">@color/material_blue_500</item> 
    <item name="colorPrimaryDark">@color/material_blue_700</item> 
    <item name="colorAccent">@color/material_green_A200</item> 
</style> 

Wenn ich versuche, diesen Code auszuführen, ich habe diesen Fehler:

error: Error: No resource found that matches the given name: attr 'colorAccent'.

... und der gleiche Fehler für colorPrimaryDark und colorPrimary! Wenn ich diesen Code ausführen in die Werte-v21/style.xml Datei, die "android:" Putting-Tag vor colorPrimary, colorPrimaryDark und colorAccent, wie:

<item name="android:colorPrimary">@color/material_blue_500</item> 
<item name="android:colorPrimaryDark">@color/material_blue_700</item> 
<item name="android:colorAccent">@color/material_green_A200</item> 

es funktioniert!

Also ... Ich verstehe nicht, wo ich falsch :(Ich habe sicherlich die v7 Support-Bibliothek aktualisiert

Jede mögliche Hilfe geschätzt wird! :)

+0

Haben Sie die Bibliothek ein importieren Und kompilieren Sie es mit Ihrem Projekt? Stellen Sie außerdem sicher, dass Sie Projekt neu erstellen ausführen, wenn Sie Android Studio verwenden. –

+0

Ich habe dieses Problem behoben, indem ich targetSdkVersion auf 21 in meiner gradle-Build-Datei gesetzt habe und 'compile 'com.android.support:appcompat-v7:20. +'' Geändert habe, um '21. +' zu verwenden. Ich verstehe es nicht, also weiß ich nicht, ob es für dich funktioniert. Dann stoßen Sie auf das Problem http://stackoverflow.com/questions/3963978/android-xml-files-why-do-predefined-colors-not-work-for-me – LarsH

+0

Siehe http: // stackoverflow. com/questions/26431676/appcompat-v721-0-0-no-resource-found-das-entspricht-dem-angegebenen-name-attr-andro – LarsH

Antwort

-2

Versuchen

parent="android:Theme.AppCompat.Light" 

Könnte Referenz:

No resource found - Theme.AppCompat.Light.DarkActionBar

+0

Ok, ich habe die Anleitung über "Hinzufügen von Bibliotheken mit Ressourcen" (https://developer.android.com/tools/support-library/setup.html#add-library), aber ich habe immer noch das gleiche Problem :( – Kurtis92