问题
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