WEB开发网
开发学院手机开发Android 开发 Android示例HelloGallery中R.styleable unresolve... 阅读

Android示例HelloGallery中R.styleable unresolved的解决办法

 2010-08-11 11:45:00 来源:WEB开发网   
核心提示:原文地址:http://blog.csdn.net/JiangBo_HIT/archive/2009/11/15/4813433.aspx今天尝试编译Android SDK中APIDemos中的程序,调试到HelloGallery的时候,Android示例HelloGallery中R.styleable unresol

原文地址:http://blog.csdn.net/JiangBo_HIT/archive/2009/11/15/4813433.aspx

今天尝试编译Android SDK中APIDemos中的程序,调试到HelloGallery的时候,在下面这段代码中:

1: public ImageAdapter(Context c) {

2: mContext = c;

3: TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);

4: mGalleryItemBackground = a.getResourceId(

5: android.R.styleable.Theme_galleryItemBackground, 0);

6: a.recycle();

7: }

编译出错,提示说android.R.styleable unresolved,在网上查了下,说R.styleable在SDK1.5中已经不再支持,所以会出现这个错误。解决方法如下:

1.在res/values目录下新建attrs.xml,在其中添加如下内容:

2.修改HelloGallery.java,将出错的那段代码:

1: public ImageAdapter(Context c) {

2: mContext = c;

3: TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);

4: mGalleryItemBackground = a.getResourceId(

5: android.R.styleable.Theme_galleryItemBackground, 0);

6: a.recycle();

7: }

修改为:

1: public ImageAdapter(Context c) {

2: mContext = c;

3: TypedArray a = obtainStyledAttributes(R.styleable.Gallery);

4: mGalleryItemBackground = a.getResourceId(

5: R.styleable.Gallery_android_galleryItemBackground, 0);

6: a.recycle();

7: }

3.重新运行就可以了

Tags:Android HelloGallery styleable

编辑录入:coldstar [复制链接] [打 印]
赞助商链接