Android示例HelloGallery中R.styleable unresolved的解决办法
来源:互联网 发布:海岛火炮升级数据 编辑:程序博客网 时间:2024/05/21 16:58
今天尝试编译Android SDK中APIDemos中的程序,调试到HelloGallery的时候,在下面这段代码中:
- public ImageAdapter(Context c) {
- mContext = c;
- TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
- mGalleryItemBackground = a.getResourceId(
- android.R.styleable.Theme_galleryItemBackground, 0);
- a.recycle();
- }
编译出错,提示说android.R.styleable unresolved,在网上查了下,说R.styleable在SDK1.5中已经不再支持,所以会出现这个错误。解决方法如下:
1.在res/values目录下新建attrs.xml,在其中添加如下内容:
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <declare-styleable name="Gallery">
- <attr name="android:galleryItemBackground">
- </attr>
- </declare-styleable>
- </resources>
2.修改HelloGallery.java,将出错的那段代码:
- public ImageAdapter(Context c) {
- mContext = c;
- TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
- mGalleryItemBackground = a.getResourceId(
- android.R.styleable.Theme_galleryItemBackground, 0);
- a.recycle();
- }
修改为:
- public ImageAdapter(Context c) {
- mContext = c;
- TypedArray a = obtainStyledAttributes(R.styleable.Gallery);
- mGalleryItemBackground = a.getResourceId(
- R.styleable.Gallery_android_galleryItemBackground, 0);
- a.recycle();
- }
3.重新运行就可以了
0 0
- Android示例HelloGallery中R.styleable unresolved的解决办法
- Android示例HelloGallery中R.styleable unresolved的解决办法
- 【转】Android示例HelloGallery中R.styleable unresolved的解决办法
- Android实例程序中Gallery报错:R.styleable unresolved解决办法
- R.styleable.gallery报错,Android中R.styleable 无法解析时候的解决办法
- Android中R.styleable 无法解析时候的解决办法
- Android中R.styleable 无法解析时候的解决办法
- Android中R.styleable 无法解析时候的解决办法
- java.lang.NoSuchFieldError: android.support.v7.appcompat.R$styleable.Theme_w的解决办法
- Android中View自定义XML属性详解以及R.attr与R.styleable的区别
- Android中View自定义XML属性详解以及R.attr与R.styleable的区别
- Android中View自定义XML属性详解以及R.attr与R.styleable的区别
- android-R.styleable
- android-R.styleable(应用)
- R.java中styleable类
- android 绕过R文件,通过代码获取styleable的属性
- 关于R.styleable的问题
- Android 中R文件消失的解决办法
- Maven快速上手
- MySQL初学
- iscroll4snap的使用备注
- 搭建hadoop,报错Could not find or load main class org.apache.hadoop.util.VersionInfo
- Editor------------------DrawGizmo
- Android示例HelloGallery中R.styleable unresolved的解决办法
- 重新开始战斗04-编程之美-寻找ID问题
- C++项目开发中加载第三方动态库的方法
- java 变长数组
- 这是第一个博客
- TOMCAT HTTPS访问配置应用
- 指向函数的指针
- CSDN上自己看了感觉不错的文章和帖子,做个备份
- 题目1545:奇怪的连通图