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

丶灬走出姿态 提交于 2019-12-13 05:24:35

问题


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:


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>


来源:https://stackoverflow.com/questions/27488183/selector-for-button-error-valid-xml-document-must-have-a-root-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!