Sometimes when we load a background image for ImageButton, the following exception occurs:
1Org.xmlpull.v1.XmlPullParserException:Binary XML file line #3: <item> tag requires a ' drawable 'attribute or child tag defining a drawable2At Android.graphics.drawable.StateListDrawable.inflate (statelistdrawable.java:178)3At Android.graphics.drawable.Drawable.createFromXmlInner (drawable.java:867)4At Android.graphics.drawable.Drawable.createFromXml (drawable.java:804)5At Com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable (resourcehelper.java:208)6At Android.content.res.BridgeTypedArray.getDrawable (bridgetypedarray.java:774)7At Android.widget.imageview.<init> (imageview.java:119)8At Android.widget.imagebutton.<init> (imagebutton.java:85)9At Android.widget.imagebutton.<init> (imagebutton.java:81)Ten At sun.reflect.GeneratedConstructorAccessor23.newInstance (Unknown Source) One At sun.reflect.DelegatingConstructorAccessorImpl.newInstance (Unknown Source) A At java.lang.reflect.Constructor.newInstance (Unknown Source) -At Android.view.LayoutInflater.createView (layoutinflater.java:586) -At Android.view.BridgeInflater.onCreateView (bridgeinflater.java:86) theAt Android.view.LayoutInflater.onCreateView (layoutinflater.java:653) -At Android.view.LayoutInflater.createViewFromTag (layoutinflater.java:678) -At Android.view.BridgeInflater.createViewFromTag (bridgeinflater.java:131) -At Android.view.LayoutInflater.rInflate_Original (layoutinflater.java:739) +At Android.view.LayoutInflater_Delegate.rInflate (layoutinflater_delegate.java:64) -At Android.view.LayoutInflater.rInflate (layoutinflater.java:711) +At Android.view.LayoutInflater.rInflate_Original (layoutinflater.java:742) AAt Android.view.LayoutInflater_Delegate.rInflate (layoutinflater_delegate.java:64) atAt Android.view.LayoutInflater.rInflate (layoutinflater.java:711) -At Android.view.LayoutInflater.inflate (layoutinflater.java:489) -At Android.view.LayoutInflater.inflate (layoutinflater.java:372) -......
The exception that appears above is usually when we want to load the image dynamically for ImageButton, and use an XML file to set the background of the toggle button. However, this exception does not affect the program to run, there are two workarounds for this exception:
1. Restart eclipse directly and then open the layout file without exception.
2. If you are using a pure color background, not a picture, then you can not directly fill in the XML file color values, you need the values folder Color.xml (or drawable.xml) set the color value, and then use.
Android Development ImageButton loading drawable file issues