想做自己想要的按键码?今天知道了selector可以按键的shape样式都包含在其中,棒极了。
selector可以理解为状态切换器,不同的状态下切换不同的样式,在传统WEB设计中就是伪类hover。shape意为定义按钮的形状。
View Code
1 <? xml version="1.0" encoding="utf-8" ?> 2 < selector xmlns:android ="http://schemas.android.com/apk/res/android" > 3 < item android:state_pressed ="true" > 4 < shape > 5 < gradient 6 android:startColor ="#ff8c00" 7 android:endColor ="#FFFFFF" 8 android:angle ="270" /> 9 10 < stroke 11 android:width ="2dp" 12 android:color ="#dcdcdc" /> 13 14 < corners 15 android:radius ="2dp" /> 16 17 < padding 18 android:left ="10dp" 19 android:top ="10dp" 20 android:right ="10dp" 21 android:bottom ="10dp" /> 22 23 </ shape > 24 25 </ item > 26 27 < item android:state_focused ="true" > 28 < shape > 29 < gradient 30 android:startColor ="#ffc2b7" 31 android:endColor ="#ffc2b7" 32 android:angle ="270" /> 33 34 < stroke 35 android:width ="2dp" 36 android:color ="#dcdcdc" /> 37 38 < corners 39 android:radius ="2dp" /> 40 41 < padding 42 android:left ="10dp" 43 android:top ="10dp" 44 android:right ="10dp" 45 android:bottom ="10dp" /> 46 47 </ shape > 48 49 </ item > 50 51 < item > 52 < shape > 53 < gradient 54 android:startColor ="#ff9d77" 55 android:endColor ="#ff9d77" 56 android:angle ="270" /> 57 58 < stroke 59 android:width ="2dp" 60 android:color ="#fad3cf" /> 61 62 < corners 63 android:radius ="2dp" /> 64 65 < padding 66 android:left ="10dp" 67 android:top ="10dp" 68 android:right ="10dp" 69 android:bottom ="10dp" /> 70 71 </ shape > 72 73 </ item > 74 75 </ selector