android 自定义控件——(五)按钮点击变色

----------------------------------按钮点击变色(源代码下有属性解释)-----------------------------------------------------

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABDgAAAGJCAMAAABYYHPKAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjNENkREQjgwOUY0MjExRTY4RjMzRDg3NTE2NUJGRkNEIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjNENkREQjgxOUY0MjExRTY4RjMzRDg3NTE2NUJGRkNEIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6M0Q2RERCN0U5RjQyMTFFNjhGMzNEODc1MT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JPk+RA6GFOCYqcYUjMLIZ/BRqEU9czb4VIMkUi3VRuSX0Kbg5EriQcCiTlZntg0W/eOpKjucAkkqJ2A8r+xcPtmfimKjEF47jyS0ptBI0yiGXcvQ5kDT2S40t1x9cCUlbk8cXFQ5tsrKwPWg8v+zjXFkgKdz0mZvt4PZCnBOVOMOhTlaWPvxYLTJ/Bbk6i2uCAVdcfVa1tc0Wrf7361J8E5V4w3E8Ob4bXDlYs5VDlivrsvJK6rnHG3DlDNSX5GXVVdq316K1g5XgRpzdiDccSjk21rf3fsz4ZQBJxz/zY297fWN88vhiw3E8MTU7v7QwujDNewAkm2ll012an52aOL7ocBwHwuqg4+OPd0W8DUAyKXr346M63AgHji8+HNqgQ1pa+L62U8SEBUiWSUrRztr3hSXpHMONc4ZDGXRMz6wv7x38+HG/qId3BLjqeoru//hxsLe8PjN9juHGecOhDjo2paWdzwsf3o7uBYuKBgf9DD6AqzfM8A8OFhUF90bffghtB6W56XMNN84fjuPA5NTWjBT8sri8srr39mAUwJV08HZvdWV5Z0mamR0PTwSOLzccajpGxqc3N+bH1Hp81q2EhAUAlyK0IrbGd8uLO5ovwbH5jc3p8ZFzZ+NvhEOLx8TkyNT0rGJuY1caA3A1SNLuzNymumlOj0+NTE4EAoG/ssn/nXCIfCj9CIfDIwCulPCkmoy/uK3/1XAASBOEAwDhAEA4ABAOAIQDAOEAAMIBgHAAIBwACAcAwgEAhAMA4QBAOAAQDgCEAwAIBwDCAYBwACAcAAgHAMIBAIQDAOEAQDgAJL3/CzAApq/gj6HT+TYAAAAASUVORK5CYII=" alt="" width="322" height="117" />

一、shape 样式:(在drawable新建--》new--》Drawable resource file 在父级标签selector添加Item )

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#73c4f3" />
<stroke android:width="2dp" android:color="#ffffff" />
<corners android:radius="20dp" />
<padding android:bottom="5dp" android:left="10dp" android:right="10dp" android:top="5dp" />
<gradient android:angle="270" android:endColor="#8accf2" android:startColor="#8accf2" android:type="sweep" />
</shape>
</item> <item>
<shape>
<solid android:color="#3fb3f6" />
<stroke android:width="2dp" android:color="#ffffff" />
<corners android:radius="20dp" />
<padding android:bottom="5dp" android:left="10dp" android:right="10dp" android:top="5dp" />
</shape>
</item>
</selector>
二、style 样式:
<style name="rectangle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">15sp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:background">@drawable/buttonclickstyle</item>
</style>

三、Button控件调用style样式:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ly.blogtest.MainActivity"> <Button
android:id="@+id/button"
style="@style/rectangle"
android:text="@string/btn1" />
</RelativeLayout>

----------------------------------按钮点击变色-----------------------------------------------------

----------------------------------item属性标记------------------------------

  • android:state_pressed 是否按下,如一个按钮触摸或者点击。
  • android:state_focused 是否取得焦点,比如用户选择了一个文本框。
  • android:state_hovered 光标是否悬停,通常与focused state相同,它是4.0的新特性
  • android:state_selected 被选中,它与focus state并不完全一样,如一个list view 被选中的时候,它里面的各个子组件可能通过方向键,被选中了。
  • android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
  • android:state_checked 被checked了,如:一个RadioButton可以被check了。
  • android:state_enabled 能够接受触摸或者点击事件
  • android:state_activated 被激活
  • android:state_window_focused

应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了

注意:如果有多个item,那么程序将自动从上到下进行匹配,最先匹配的将得到应用。(不是通过最佳匹配)

如果一个item没有任何的状态说明,那么它将可以被任何一个状态匹配。

----------------------------------item属性标记------------------------------

按钮形状、颜色属性请结合查看  http://www.cnblogs.com/LOVEJIEYING/p/6016319.html

上一篇:Caused by: java.lang.NoClassDefFoundError: freemarker/cache/TemplateLoader


下一篇:Caused by: java.lang.ClassNotFoundException: javassist.ClassPool