0

I have three image for Button, using png format.

I have made a Selector as below:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- pressed -->
<item android:state_pressed="true" android:drawable="@drawable/press_pdgmap" />

<!-- hover -->
<item android:state_focused="true" android:drawable="@drawable/hover_pdgmap2" />

<!-- default -->
<item android:drawable="@drawable/hover_pdgmap" />

</selector>

But red tag appear in line pressed, hover, and default, it says

Top level element is not completed, Valid XML document must have a root tag

note: I'm using Android Studio

11
  • This might help stackoverflow.com/questions/4445525/… Commented Dec 15, 2014 at 16:09
  • You forgot to put <selector> node as parent. [Check this][1] [1]: stackoverflow.com/questions/14023886/android-button-selector Commented Dec 15, 2014 at 16:10
  • I'm already try this Question and this but still got red tag @codeMagic Commented Dec 15, 2014 at 16:50
  • Then you should have mentioned that to begin with. Have you tried cleaning and rebuilding your project since making that change? Commented Dec 15, 2014 at 16:56
  • Sorry if have not mention it, because i think it's different problem, i already try to change image name, cleaning, and rebuilding project.. but stil the same @codeMagic Commented Dec 15, 2014 at 17:07

1 Answer 1

1

Top level element should be selector and XML file should be placed in the res/drawable/ directory. Example:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_pressed"
          android:state_pressed="true" />
    <item android:drawable="@drawable/button_focused"
          android:state_focused="true" />
    <item android:drawable="@drawable/button_default" />
</selector>
Sign up to request clarification or add additional context in comments.

7 Comments

I have moved selector to top like example, and xml file already placed in res/drawable folder, but still got red tag @Vadim
If your xml is the same as in example and placed in the right folder then everything should work. Try to run gradle clean task. Maybe file name or xml contains illegal characters?
@Ade06 also I have tried to copy your xml to Android Studio project (with my drawables) and it's working fine. XML in your example is valid selector.
i dont what wrong. i look into android studio everything look's fine, this my pic about the code pic @Vadim
@Ade06 file name is padangmap but should be padangmap.xml
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.