In meiner app konvertieren Ich definiere Farbe Attribute, die ich in einem benutzerdefinierten Thema gesetzt:Android ziehbar xml Kann nicht Farbe Ausnahme für API 10
res/Werte/attrs.xml
<resources>
<attr name="bbColorPrimary" format="color|reference" />
</resources>
res /values/colors.xml
<resources>
<color name="white">#ffffff</color>
</resources>
res/Werte/style.xml
<style name="MyStyle" parent="@style/Theme.AppCompat.NoActionBar">
<item name="bbColorPrimary">@color/white</item>
</style>
res/ziehbar/background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<solid android:color="?attr/bbColorPrimary" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/transparent" />
</shape>
</item>
</selector>
res/drawable/background.xml
als Hintergrund einiger Schaltflächen. Die App stürzt beim Aufblasen des res/drawable/background.xml
Datei, mit folgender Ausnahme:
...
Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
at android.content.res.TypedArray.getColor(TypedArray.java:326)
at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:748)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:172)
....
Es funktioniert auf API-Ebenen höher als 10. Wenn ich die ?attr/bbColorPrimary
entfernen es funktioniert gut, obwohl viele andere ?attr/..
Anrufe in andere Ressourcendateien eingestellt werden . Ich verwende keine versionsspezifischen Ressourcenordner.
Was mache ich hier falsch?
Auch bei API = 16 I einen Absturz haben, API => 21 jedoch in Ordnung sind. – Ruocco
@ Omcira danke für die Erwähnung. Kann auch mit API = 15 bestätigen. –
Selbst mit API 17, ich denke, es ist in <21 crash, weil in meinem Lollipop-Gerät gut funktionieren. –