Quando guardo misc. Esercitazioni ed esempi su Android quando si tratta di specificare i colori molto spesso vedo costanti come @color/red
o @color/black
ecc. Per qualche strana ragione che non funziona MAI per me! Devo sempre specificare i colori usando la notazione "#RGB", #ARGB, ..., #AARRGGBB.File .xml Android: Perché i colori predefiniti non funzionano per me?
Non appena cerco di utilizzare una di quelle costanti mnemoniche come ad es. "@ Colore/rosso" Mi è toccato messaggi di errore come questi:
[...] C:\Users\mmo\Test\res\drawable\edit_text.xml:5: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/orange').
[...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:3: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black').
[...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:4: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black').
[...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:5: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/green').
[...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:6: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black').
Perché è così? Perché non posso usare queste costanti predefinite? Devo prefissarli con un nome di pacchetto (ho provato @android:color/red
ma questo ha causato solo un errore diverso)? Devo specificare questi colori da solo? Se sì: come e dove? Qualche idea o suggerimento?
Michael
Ho creato un file di questo tipo nella mia app ora e ho definito un gruppo di colori di default lì e ora posso effettivamente usare tali colori con nome. Apparentemente tutti quegli esempi che ho visto presumevano l'esistenza di un tale file senza mai affermarlo esplicitamente. Così ho falsamente arrivato alla conclusione che questi valori erano predefiniti. – mmo
Vedere http://stackoverflow.com/a/3964048/632951 anche – Pacerier