Android中R.styleable 无法解析时候的解决办法
2013-04-20 11:25
183 查看
今天尝试编译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();
}
相关文章推荐
- Android中R.styleable 无法解析时候的解决办法
- R.styleable.gallery报错,Android中R.styleable 无法解析时候的解决办法
- android-webview无法解析网页中的mjpeg文件的解决办法
- 华为手机 关于Android真机调试的时候logcat中无法输出调试信息的解决办法
- Android中R.styleable 无法解析时候的解决办法
- Android中出现Error:In <declare-styleable> FontFamilyFont, unable to find attribute android:font 解决办法
- Android真机调试的时候logcat中无法输出调试信息的解决办法
- 启动plSql时候报ORA-12541:TNS:tns:无法解析指定的连接标识符的解决办法(org11)
- Android Studio for Ubuntu 14.04 无法输入中文解决办法
- Android WebView无法弹出软键盘的原因及解决办法
- android、电脑可以播放.mp4的视频,ios无法播放解决办法
- android程序卸载后无法删除桌面快捷方式的解决办法
- VC++ Error LNK2001无法解析的外部符号 的几种情况及解决办法
- Xamarin Android SDK无法更新的解决办法
- android WebView使用cmwap无法联网解决办法
- Error LNK2001 无法解析的外部符号 的几种情况及解决办法
- js无法获取style样式的问题解析与解决方法
- Visual Studio 2008 error LNK2019 错误解决办法(无法解析的外部符号 _WinMain)