Android中R.styleable 无法解析时候的解决办法
2014-08-01 08:23
260 查看
今天尝试编译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();
}
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();
}
相关文章推荐
- 启动plSql时候报ORA-12541:TNS:tns:无法解析指定的连接标识符的解决办法(org11)
- Android中R.styleable 无法解析时候的解决办法
- Android中R.styleable 无法解析时候的解决办法
- R.styleable.gallery报错,Android中R.styleable 无法解析时候的解决办法
- 断开网络dom4j无法解析有网络dtd的xml文件的解决办法
- SQLl2005 无法创建数据库关系图时候解决办法
- WINCE 6.0 VS2008 中使用WINSOCK函数产生:无法解析的外部符号 等错误的解决办法
- 使用U盘时候的"无法停用通用卷"的解决办法
- IE6中运行EXTJS中某些组件无法解析DOMINO产生的JSON数据问题的解决办法
- “无法解析此名称,此项作业失败“的错误解决办法一例
- C++中使用类模板时出现:“error LNK2019: 无法解析的外部符号”的解决办法
- 用Think Pad 系统升级程序ThinkVantage System Update时候提示 无法连接代理服务器 的解决办法
- SQL2005删除用户的时候,产生“数据库主体在该数据库中拥有架构,无法删除”的解决办法
- 64位win7下PL/SQL Developer 报“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法[转帖]
- IIS ora-12154服务器无法解析标示符的解决办法
- 无法解析的外部符号 _main解决办法(转)
- bstr error LNK2019: 无法解析的外部符号 "char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)" 的解决办法
- 使用PLSQL Developer时,“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法
- 关于部分ghost版windowsXP sp2系统下的iis5无法解析、运行asp页面的解决办法
- 使用PLSQL Developer时,出现“ORA-12154: TNS:无法解析指定的连接标识符”解决办法