Android Gallery sample program error: R.styleable unresolved Solution

Android Gallery sample program error: R.styleable unresolved Solution

imageView = new ImageView(MainActivity.this);

TypedArray typedArray = obtainStyledAttributes(R.styleable.Gallery);

imageView.setBackgroundResource(typedArray.getResourceId(R.styleable.Gallery_android_galleryItemBackground,0));

The above code compiler error, suggesting that styleable can not be resolved or is not a field, checked on the net, the said R.styleable no longer supported in SDK1.5 in, so this error.

Solutions are as follows:

  • New attrs.xml at res / values ​​directory, add the following in which:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Gallery">  
        <attr name="android:galleryItemBackground">  
        </attr>  
    </declare-styleable> 
</resources>
Published 11 original articles · won praise 3 · Views 4982

Guess you like

Origin blog.csdn.net/OHWWWendy/article/details/78107015