22

While taking a course, I was instructed to make an xml selector for a Button. The course said to make a new Android xml in Eclipse, but i am using Android Studio.

Also when I custom write the code it gives me an error. It says "element selector must be declared".

as you can see selector is an error

Got code from here: Android: How to Make A Drawable Selector.

Does anyone know how to do this in Android Studio?

Snostorp
  • 544
  • 1
  • 8
  • 14
Menachem Hornbacher
  • 2,080
  • 2
  • 24
  • 36
  • 5
    Is that file of yours under **res/drawable/** folder? – Marko Jan 01 '15 at 19:46
  • Where does it give you the error "element selector must be declared"? Can you put it in a screenshot? The XML is correct (though the states are incorrect given the naming of the drawable). – ataulm Jan 01 '15 at 19:46
  • yes it is, and that is a direct quote from mousing over the selector word – Menachem Hornbacher Jan 01 '15 at 19:51
  • Can you please check again that your file is not under **res/values/** folder, but in **res/drawable/** folder where it should be! I have checked, and **values** folder, gives that exact error. – Marko Jan 01 '15 at 20:01
  • yah, messed up. but do you know how to add one within the GUI? – Menachem Hornbacher Jan 01 '15 at 20:03
  • 3
    Just right click the **res/drawable/** folder **->** New **->** Drawable resource file – Marko Jan 01 '15 at 20:05
  • @Marko what is the status of anim or anim-v21 folders? Why doesn't it work in anim folder? – Sudhir Singh Khanger Nov 30 '16 at 08:00
  • 1
    @SudhirKhanger I guess it is because the Android framework expects you to put certain types of things into their designated folder (drawables, selectors, vector images into *drawable* folder, strings, dimensions, integers into *values* folder, etc..). Anim folder doesn't have access for instance to tag mentioned above, but has access to it's own set of tags (like , , ,...). My guess is for reasons like, optimization in loading resources, etc.. – Marko Nov 30 '16 at 16:29

2 Answers2

37

Though it is already answered in the comment, enter image description here

Dev Gurung
  • 1,290
  • 14
  • 16
4

First of all, there will be no drawable folder when establish a new Android Project in Android Studio likes Eclipse does. Right click on res folder--> New--> Android Resource Directory--> resource type--> drawable, and now you get a drawable folder, and then, you can add your new drawable resource file, selector, shape and .etc

Roger Alien
  • 3,040
  • 1
  • 36
  • 46
3h3
  • 722
  • 5
  • 6