"<item> tag requires a 'drawable' attribute"-selector设置颜色不成功-解决方案
来源:互联网 发布:戴隐形眼镜游泳 知乎 编辑:程序博客网 时间:2024/05/21 10:08
Android中Button控件实现触摸时背景颜色改变的效果,原实现方式如下:
Button中引用android:background="@drawable/button_background_selector"
在文件夹drawable下定义button_background_selector.xml文件,如下:
这种方法在运行时报错如下:
05-06 18:14:42.730: E/AndroidRuntime(24114): Caused by: org.xmlpull.v1.XmlPullParserException: BinaryXML file line #4: tag requires a 'drawable' attribute or child tagdefining a drawable05-06 18:14:42.730: E/AndroidRuntime(24114): atandroid.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:178)05-06 18:14:42.730: E/AndroidRuntime(24114): atandroid.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:885)05-06 18:14:42.730: E/AndroidRuntime(24114): atandroid.graphics.drawable.Drawable.createFromXml(Drawable.java:822)05-06 18:14:42.730: E/AndroidRuntime(24114): atandroid.content.res.Resources.loadDrawable(Resources.java:2045)05-06 18:14:42.730: E/AndroidRuntime(24114): ... 31 more
解决方法:
Button中引用background属性不变
更改button_background_selector.xml文件,如下:
并在colors.xml文件中增加如下定义:
问题解决。这还真是个新奇的问题,以前倒是没有碰到过。
0 0
- "<item> tag requires a 'drawable' attribute"-selector设置颜色不成功-解决方案
- "<item> tag requires a 'drawable' attribute"-selector设置颜色不成功-解决方案
- "<item> tag requires a 'drawable' attribute"-selector设置颜色不成功-解决方案
- <item> tag requires a 'drawable' attribute"-selector设置颜色不成功-解决方案
- <item> tag requires a 'drawable' attribute"-selector设置颜色报错-原因及解决方案
- android背景设置报错 <item> tag requires a 'drawable' attribute or child tag defining a drawable
- android背景设置报错 <item> tag requires a 'drawable' attribute or child tag defining a drawable<转>
- android背景设置报错 <item> tag requires a 'drawable' attribute or child tag defining a drawable
- android背景设置报错 <item> tag requires a 'drawable' attribute or child tag defining a drawable
- android背景设置报错 <item> tag requires a 'drawable' attribute or child tag defining a drawable
- <item> tag requires a 'drawable' attribute or child tag defining a drawab
- <item> tag requires a 'drawable' attribute or child tag defining a drawab
- <item> tag requires a 'color' attribute or child tag defining a drawable
- Binary XML file line #4: <item> tag requires a 'drawable' attribute or child tag defining a drawable
- Binary XML file line #3: <item> tag requires a 'drawable' attribute or child tag defining a drawable
- textcolor 设置selecter 报错: <item> tag requires a 'color' attribute or child tag defining a drawab
- tag requires a 'drawable' attribute or child tag defining a drawable 错误解决
- AndroidStudio-xml预览布局无法正常显示tag requires a 'drawable' attribute or child tag defining a drawable
- WITH AS 用法示例
- QTableView
- openstack用nfs实现live migration
- 安卓开发一些细节
- 【android】只让本应用程序的webview加载网页而不调用外部浏览器的办法
- "<item> tag requires a 'drawable' attribute"-selector设置颜色不成功-解决方案
- Android Service服务被杀死后重启
- Android WebView 加载的网页不能缩放相关问
- Android WebView 软键盘遮挡输入框问题的解决方法
- Android 将SQLite数据保存在SD卡
- android 横竖屏切换时 不重新走生命周期
- 如何删除电脑中使用过的COM端口
- MySQL主从同步
- 跨平台的音视频即时通讯SDK