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

Answer
    • Same error happens to me. Just upgraded the gradle to the latest (as per the warning message!) and zap! won't even compile anymore. Thanks, Google!

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>
  • 1
Reply Report
      • 1
    • thx for your prompt response. Now works again, but wonder why it was working no problem for almost a year and now since I upgrade the android Studio stop working?
      • 1
    • I don't know about that, maybe Android Studio made some changes upon updation. Though I always use selector tag inside drawable resource to implement custom design on buttons and imageviews. Thanks for asking!

a ColorStateList selector does not belong inside a resources node.

you have to put that into an extra file.

  • 0
Reply Report
      • 2
    • @QQapps18 this was always illegal - while now it is being enforced (along a few other things)... while my answer provides an easy solution to fix it. "it once worked", this is anything but a valid argument... because this does not help, at all. the other answer suggested about the same, while I think I was a tad quicker. please accept the answer if it helps.

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions