Android Development ImageButton loading drawable file issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.