QQapps18
QQapps18

Reputation: 31

android studio 3.3.1 color..xml Error: Can't determine type for tag '<selector xmlns:android="http://schemas.android.com/apk/res/android">

I have a project that was working perfect in the last version of Android Studio. I decided to upgrade to the version 3.3.1, and now the color.xml present a error, try to rebuild, clean, even change the minSdkVersion, nothing work.

The following is the original code

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#000000</color>
    <color name="colorPrimaryDark">#3e2723</color>
    <color name="colorAccent">#3e2723</color>
    <color name="blackTransparent">#ad000000</color>

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true"
          android:color="#ffcc0000"/>
    <item android:state_checked="false"
          android:color="#ff669900"/>
</selector>

</resources>

the error msg is

...\app\src\main\res\values\colors.xml: Error: Can't determine type for tag '<selector xmlns:android="http://schemas.android.com/apk/res/android">

I'll really appreciate any feedback in this issue

Upvotes: 2

Views: 7100

Answers (2)

rvd
rvd

Reputation: 119

Put this inside a drawable resource file and set the background of whatever view (e.g. button, image) to this drawable resource. It'll work!

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_checked="true"
          android:color="#ffcc0000"/>
    <item android:state_checked="false"
          android:color="#ff669900"/>
</selector>

Upvotes: 2

Martin Zeitler
Martin Zeitler

Reputation: 76859

a ColorStateList selector does not belong inside a resources node.

you have to put that into an extra file.

Upvotes: 0

Related Questions