异常日志:
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: <item> tag requires a 'drawable' attribute or child tag defining a drawable
产生原因:
我的一个button按钮的background属性中设置成"@color/button_text_selector",按照异常来说,这个background这个属性的值必须是drawable类型的,不能是color类型。
drawable&color:
本来我是想给button设置一个selector,让按钮背景正常状态下是一个颜色值,点击状态下背景又是另外一个值,但是没想到报了这样一个错误,既然background只能设置为drawable,那我就写一个drawable的selector给button设置不同状态下的颜色值,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 点击状态下的效果 -->
<item android:state_pressed="true">
<shape>
<!-- 设置背景填充色为黑色 -->
<solid android:color="@color/black"/>
<!-- 设置边框宽度为1dp,边框颜色为白色 -->
<stroke android:width="1dp" android:color="@color/white" />
<!-- 设置按钮圆角半径为5dp -->
<corners android:radius="5dp" />
<!-- 设置按钮中间文字距上下左右都为10dp的间距 -->
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
<!-- 正常状态下(非点击)的效果 -->
<item android:state_pressed="false">
<shape>
<!-- 设置背景填充色为白色 -->
<solid android:color="@color/white"/>
<!-- 设置边框宽度为1dp,边框颜色为黑色 -->
<stroke android:width="1dp" android:color="@color/black" />
<!-- 设置按钮圆角半径为5dp -->
<corners android:radius="5dp" />
<!-- 设置按钮中间文字距上下左右都为10dp的间距 -->
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape>
</item>
</selector>
这样即可对不同状态下的button设置颜色值了,还可以设置其他圆角之类的效果;当然这个只能设置按钮背景的效果,但是文字是没有点击效果的,如果使用我上面缩写的selector,那么就会在按下按钮的时候出现这个效果:
在按钮被点击的时候背景色和字体颜色混成一体,所以我们最好同时给字体颜色设置一个selector,如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- button点击状态下的字体颜色 -->
<item android:state_pressed="true" android:color="@color/white"></item>
<!-- button正常状态下的字体颜色 -->
<item android:state_pressed="false" android:color="@color/black"></item>
</selector>
最后在界面layout中设置button属性:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button"
android:background="@drawable/button_selector"
android:textColor="@color/button_text_selector"/>
这样我们的button效果就会如图:
button正常状态下为白底黑字黑边,点击状态下为黑底白字白边。
demo下载:
http://download.csdn.net/detail/zhufuing/6974387
分享到:
相关推荐
tlsNet.zip<br>TILISOFT Internet ActiveX Controls - Retrieve HTML pages from the Net - Post data to HTTP server <END><br>19 , pingmon.zip<br>A ping monitor for the network administrator. Based on API ...
on left and right side of a text box.<END><br>40,Assist.zip<br>A simple application with source code which shows how to save the contents of a rich text box without the help of common dialog box.<END>...
<br><br> m_hDC = CreateCompatibleDC(0) <br> If (m_hDC <> 0) Then <br> If (CreateDIB(m_hDC, lWidth, lHeight, m_hDIb)) Then <br> m_hBmpOld = SelectObject(m_hDC, m_hDIb) <br> Create = True <br> Else <br...
<br>A DIB (Device Independent Bitmap) Section is a GDI object like a standard DIB but which additionally provides a pointer to the memory used to store the bitmap bits to which the creating ...
============================================<br><br>Out of the box, Tomcat 5.5 requires the Java 2 Standard Edition Runtime<br>Environment (JRE) version 5.0 or later. However, you can also run Tomcat...
Windows 95 must be OSR2 or later version<br><br>32MB (or more) of RAM<br><br>10GB (or more) hard disk is recommended (a 74 minute CD image requires 650-700MB)<br><br>One or more bus-mastering SCSI ...
1,CODE_UPLOAD137411132001.zip<br>A 3Dimensional park with lolly pop trees and flying birds. Programmed with Direct3D (Retained Mode). A good program to learn some simple direct3d in. Requires the ...
determined the<br>multicast capacity in a network of lossless links and showed that achieving the multicast<br>capacity requires in general the use of network coding. This thesis presents the ...
Brooks , Ed Tittel <br><br>Paperback: 408 pages <br>Publisher: Que (March 20, 2004) <br>Language: English <br>ISBN-10: 0789731088 <br>ISBN-13: 978-0789731081 <br><br><br><br>The A+ certification is ...
(case=9436) <br>STL list<> and vector<> member lists appear correctly following a "using namespace std::list" or "using namespace std::vector" directive. (case=12345) 7226 <br>Empty C++ preprocessor ...
Build 1616<br>requires software maintenance through 2007.11.08. (Release candidate.) <br>New! Create VA Snippet from selection. <br>.NET references are now parsed even when 'parse all files' is ...
<br><br>A smart collection of 100 insider tips and tricks, Ajax Hacks covers all of the technology's finer points. Want to build next-generation web applications today? This book can show you how. ...
<br><br>Build 1640<br>requires software maintenance through 2008.05.22. (General release.) <br>Fixed spurious coloring of string literals in VC6. (case=16454) 7565 <br>Fixed Asian character display ...
Subclipse 1.4.x requires Subversion 1.5.0 version of JavaHL/SVNKit <br><br>Links for 1.4.x Release:<br>Changelog: http://subclipse.tigris.org/subclipse_1.4.x/changes.html<br>Eclipse update site URL: ...
有些服务器的MDAC版本还是2.5的,如果MDAC的版本太低的话,会有如下出错信息:<br> The .Net Data OLE DB Provider(System.Data.OleDb) requires Microsoft Data Access Components(MDAC) version 2.6 or later....
NULL 博文链接:https://yxhcquedu.iteye.com/blog/861110
MySQL 5.1 帮助文档 chm格式<br><br>MySQL 5.1 Reference Manual<br>Copyright 1997-2006 MySQL AB <br><br>This documentation is NOT distributed under a GPL license. Use of this documentation is subject to ...
--analyzer <arg> for query, (KeywordAnalyzer | StandardAnalyzer) (defaults to KeywordAnalyzer) --fields <arg> fields to include in output (defaults to all) -i,--index <arg> index (required) --...