0

J'ai vu un certain nombre de questions SO sur cette erreur, mais tous avaient un problème commun, qui est qu'ils essayaient d'utiliser les attributs v21 sur les anciennes versions ou ils avaient un targetSDKVersion inférieur, mais ce n'est pas le cas dans mon application.Aucune ressource trouvée qui correspond au prénom: attr 'accentColor'

Note: J'ai supprimé les dossiers déjà présents values-v11 et values-v14 du projet, si ce qui compte.

L'erreur du compilateur est comme suit:

[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] D:\CodingMyHeart\WORKSPACES\EclipseWorkspaces\Workspace of Android Practice One\MaterialDesignGoogleNowLikeSearchBoxThree\res\values\styles.xml:19: error: Error: No resource found that matches the given name: attr 'accentColor'. 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] D:\CodingMyHeart\WORKSPACES\EclipseWorkspaces\Workspace of Android Practice One\MaterialDesignGoogleNowLikeSearchBoxThree\res\values\styles.xml:17: error: Error: No resource found that matches the given name: attr 'primaryColor'. 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] D:\CodingMyHeart\WORKSPACES\EclipseWorkspaces\Workspace of Android Practice One\MaterialDesignGoogleNowLikeSearchBoxThree\res\values\styles.xml:18: error: Error: No resource found that matches the given name: attr 'primaryColorDark'. 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] D:\CodingMyHeart\WORKSPACES\EclipseWorkspaces\Workspace of Android Practice One\MaterialDesignGoogleNowLikeSearchBoxThree\res\values-v21\styles.xml:7: error: Error: No resource found that matches the given name: attr 'android:accentColor'. 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] D:\CodingMyHeart\WORKSPACES\EclipseWorkspaces\Workspace of Android Practice One\MaterialDesignGoogleNowLikeSearchBoxThree\res\values-v21\styles.xml:5: error: Error: No resource found that matches the given name: attr 'android:primaryColor'. 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] D:\CodingMyHeart\WORKSPACES\EclipseWorkspaces\Workspace of Android Practice One\MaterialDesignGoogleNowLikeSearchBoxThree\res\values-v21\styles.xml:6: error: Error: No resource found that matches the given name: attr 'android:primaryColorDark'. 
[2015-08-08 14:30:23 - MaterialDesignGoogleNowLikeSearchBoxThree] 

J'ai appcompat_v7 déjà inclus dans le projet, et il est une autre bibliothèque nommée android-support-v7-appcompat disponible:

enter image description here

SSCCE:

res/valeurs/Colors.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="primaryColor">#64FFDA</color><!-- Light ferozi --> 
    <color name="primaryColorDark">#1DE9B6</color><!-- Darker ferozi --> 
    <color name="accentColor">#E94F37</color><!-- Close to red --> 
</resources> 

res/valeurs/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="Theme.AppCompat.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"> 
     <item name="primaryColor">@color/primaryColor</item> 
     <item name="primaryColorDark">@color/primaryColorDark</item> 
     <item name="accentColor">@color/accentColor</item> 
    </style> 

</resources> 

res/valeurs-v21/styles.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <item name="android:primaryColor">@color/primaryColor</item> 
     <item name="android:primaryColorDark">@color/primaryColorDark</item> 
     <item name="android:accentColor">@color/accentColor</item> 
    </style> 
</resources> 

Manifest

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.materialdesigngooglenowlikesearchboxthree" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="22" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.materialdesigngooglenowlikesearchboxthree.MainActivity" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/hello_world" /> 

</RelativeLayout> 

MainActivity.java

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

Répondre

1

Vous utilisez les propriétés mal. C'est colorPrimary et non primaryColor. Suivez this.

Modifier - Pour votre référence

<resources> 
<!-- inherit from the material theme --> 
    <style name="AppTheme" parent="android:Theme.Material"> 
    <!-- Main theme colors --> 
    <!-- your app branding color for the app bar --> 
    <item name="android:colorPrimary">@color/primary</item> 
    <!-- darker variant for the status bar and contextual app bars --> 
    <item name="android:colorPrimaryDark">@color/primary_dark</item> 
    <!-- theme UI controls like checkboxes and text fields --> 
    <item name="android:colorAccent">@color/accent</item> 
    </style> 
</resources>  

Modifier

propriétés ActionBar sont différentes de celles AppCompat propriétés.Vous devez donner explicitement les propriétés du thème comme this.

Exemple

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<!-- the theme applied to the application or activity --> 
<style name="CustomActionBarTheme" 
     parent="@style/Theme.Holo"> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item> 
    <item name="android:actionMenuTextColor">@color/actionbar_text</item> 
</style> 

<!-- ActionBar styles --> 
<style name="MyActionBar" 
     parent="@style/Widget.Holo.ActionBar"> 
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item> 
</style> 

<!-- ActionBar title text --> 
<style name="MyActionBarTitleText" 
     parent="@style/TextAppearance.Holo.Widget.ActionBar.Title"> 
    <item name="android:textColor">@color/actionbar_text</item> 
</style> 

<!-- ActionBar tabs text styles --> 
<style name="MyActionBarTabText" 
     parent="@style/Widget.Holo.ActionBar.TabText"> 
    <item name="android:textColor">@color/actionbar_text</item> 
</style> 
</resources>  

Mais son conseillé d'utiliser ToolBar. qui a beaucoup de fonctionnalités et qui sont utilisées selon votre style. Celui-ci est un exemple typique pour ToolBar.

<android.support.v7.widget.Toolbar 
android:id=”@+id/my_awesome_toolbar” 
android:layout_height=”wrap_content” 
android:layout_width=”match_parent” 
android:minHeight=”?attr/actionBarSize” 
android:background=”?attr/colorPrimary” />  

Pour plus, vous pouvez consulter this.

+0

Hey cela a résolu l'erreur. Mais ces couleurs ne sont pas appliquées. Il s'agit simplement de choisir la couleur de la barre d'action claire ou sombre selon que j'utilise le thème de base 'AppCompat.Light' ou' AppCompat.Dark'. Que devrais-je faire? – Solace

+0

Utilisez-vous par défaut 'actionBar' ou' toolbar'? – ImMathan

+0

ActionBar par défaut. Je n'ai ajouté aucun code à quoi que ce soit. Vous pouvez voir le SSCCE ci-dessus. – Solace