Android实例程序中Gallery报错:R.styleable unresolved解决办法
imageView = new ImageView(MainActivity.this);
TypedArray typedArray = obtainStyledAttributes(R.styleable.Gallery);
imageView.setBackgroundResource(typedArray.getResourceId(R.styleable.Gallery_android_galleryItemBackground,0));
以上代码编译出错,提示说styleable cannot be resolved or is not a field,在网上查了下,说R.styleable在SDK1.5中已经不再支持,所以会出现这个错误。
解决方法如下:
- 在res/values目录下新建attrs.xml,在其中添加如下内容:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery">
<attr name="android:galleryItemBackground">
</attr>
</declare-styleable>
</resources>