java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 at API Launch21
-
java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
There's a mistake in testing API passenger21 (i.e., everything falls down, even though 5+ of the Android version works). Plus
AndroidStudio
releases warnings in filesxml-drawable
but doesn't give any clues. What's the problem?My fault.What do we do?Here.
xml drawable
:<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="?colorPrimary"
android:startColor="@android:color/transparent"/></shape>
-
According to the https://stackoverflow.com/a/13471695/3212712 The problem is before
API 21
No colour attachments can be usedxml-drawable
references to colours@color
♪ We're gonna have to convert the folded file so:<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="@color/my_awesome_color_that_i_use_as_color_primary_in_my_awesome_theme"
android:startColor="@android:color/transparent"/></shape>
If you and I need to use the same thing.
xml-drawable
But with different colors for different topics, nothing remains but:Create an attribut-sniff.
xml-drawable
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- по ссылке утверждают, что надо обязательно только lowerCase пользовать в названии -->
<attr name="my_drawable" format="reference" />
</resources>
To designate a reference to a separate
xml-drawable
in this attribution to every subject<style name="MyTheme" parent="@android:style/Theme.NoTitleBar">
<item name="my_drawable">@drawable/my_drawable_for_this_theme</item>
</style>
Use this attribut where you need to.
TextView
<TextView android:background="?my_drawable" />
Of course not to forget to create one.
xml-drawable
with specific colour for each topic