2016-05-27 4 views
4

Ich wollte eine bestehende App ändern, um Material Design zu verwenden. Ich verließ die res/Werte/styles.xml wie folgt aus:Attribut Fehler beim Wechsel zu Material Design

<resources> 
<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.DayNight"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 
</resources> 

I definiert eine res/Werte-v21/styles.xml und das Material Design Thema setzen dort:

<resources> 
<!-- Base application theme. --> 
<style name="AppTheme" parent="android:Theme.Material"> 
    <!-- Customize your theme here. --> 
    <item name="android:colorPrimary">@color/colorPrimary</item> 
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="android:colorAccent">@color/colorAccent</item> 
</style> 
</resources> 

Jetzt, Wenn ich versuche, es auf einem Lollipop + -Gerät in der Vorschau anzuzeigen oder auszuführen, ist das Design durcheinander (Textbox-Texte werden unter anderem nicht angezeigt). Es gibt auch diesen Fehler im Design Vorschau:

java.lang.NumberFormatException: Attribute '?attr/colorAccent' not found. Are you using the right theme? 
at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:76) 
at android.content.res.BridgeTypedArray.getColorStateList(BridgeTypedArray.java:372) 
at android.widget.TextView.<init>(TextView.java:750) 
at android.widget.TextView.<init>(TextView.java:671) 
at android.widget.TextView.<init>(TextView.java:667) 
at sun.reflect.GeneratedConstructorAccessor115.newInstance(Unknown Source) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:107) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:149) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835) 
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:394) 
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:229) 
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426) 
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350) 
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:520) 
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:508) 
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:967) 
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:508) 
at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:75) 
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:620) 
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:617) 
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:371) 
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:617) 
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:639) 
at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$7.run(AndroidDesignerEditorPanel.java:519) 
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:337) 
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:327) 
at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:271) 
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:286) 
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:244) 
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234) 
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) 
at com.intellij.util.Alarm$Request$1.run(Alarm.java:352) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
at java.lang.Thread.run(Thread.java:745) 

In meiner gradle Datei, ich bin mit:

compileSdkVersion 23 
buildToolsVersion "23.0.3" 

mit:

minSdkVersion 15 
targetSdkVersion 23 

und:

dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
testCompile 'junit:junit:4.12' 
compile 'com.android.support:appcompat-v7:23.4.0' 
} 

Screenshot of issue

Habe ich vergessen, etwas zu tun, oder vergessen, etwas zu berücksichtigen? Vielen Dank.

Antwort

-1

Wenn Sie nicht die Support-Bibliothek verwenden, sollten Sie diese Attribute mit android Präfix:

<resources> 
<!-- Base application theme. --> 
<style name="AppTheme" parent="android:Theme.Material"> 
    <!-- Customize your theme here. --> 
    <item name="android:colorPrimary">@color/colorPrimary</item> 
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="android:colorAccent">@color/colorAccent</item> 
</style> 
</resources> 
+0

Ich denke, ich benutze die Support-Bibliothek. Ich habe jetzt 2 styles.xml. Eins im Verzeichnis "values" und das andere im Verzeichnis "values-v21". Die v21 hat nun das Material Design Theme mit dem Android Prefix, allerdings bekomme ich immer noch sehr ähnliche Fehler. (Zum Beispiel: Ausnahme beim Rendern: Attribut '? Attr/colorAccent' nicht gefunden. Verwenden Sie das richtige Thema?) – Bob

+0

Wenn Sie die Support-Bibliothek verwenden, benötigen Sie nur einen v21-Stil, wenn Sie Stile für v21 anpassen möchten. Andernfalls reicht eine einzelne styles.xml-Targeting-Support-Bibliothek aus. – Egor

+0

gemäß der Dokumentation, wenn ich Abwärtskompatibilität will, brauche ich zwei styles.xml: https://developer.android.com/training/material/compatibility.html#Theme – Bob

0

Könnte es sein, dass Sie verwenden Farbe/accentColor in einem der Layouts statt @ Farben/Akzentfarbe ?

+0

Ich suchte alle meine Layout-Dateien für jede Instanz von 'accentColor', konnte aber keine finden ... nicht sicher, was das ist – Bob

0

Ich hatte den gleichen Fehler. Entfernen Sie die folgende Zeile aus dem Layout-Attribute es gelöst:

android:theme="@style/AppTheme" 

(gelöscht it)

Der Fehler verschwunden.