Selector for button error "Valid XML document must have a root tag"

4.2k Views Asked by At

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

1

There are 1 best solutions below

7
On BEST ANSWER

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>