shape 可以實現一些你想要的效果, 比如有時候 你在一個 button 獲得焦點,按下 ,時要改變圖片 以讓客戶有更好的體驗感覺。
shape 就可以改變這些 控制項的一些 屬性, 可以說 讓你在一個小項目中實現 獲得焦點,按下 統一的效果和 風格吧, 而且這樣超級方便呢。
在 你的 drawable檔案夾下面 建立1個xml檔案,比如 selector.xml
shape裡面有這麼幾個屬性,其實很簡單:
<shape>
<solid android:color=""/> 實心屬性: 什麼顏色
<gradient
android:startColor="" 漸層屬性: 1.開始顏色
android:endColor="" 2.結束顏色
android:angle="90" /> 3.angle: 漸層的角度 必須為45度的倍數
//漸層平常預設是 線性漸層 android:type="linear",
// 想要變成 放射狀漸層 android:type="radial",放射狀漸層需要指定半徑android:gradientRadius="30"。
<stroke 描邊屬性:
android:width="3dp" 1.描邊的寬度
android:dashWidth="6dp" 2.表示橫線的寬度
android:dashGap="3dp" 3.表示隔開的距離
android:color="" /> 4.描邊的顏色
<corners 圓角屬性:
android:topRightRadius="20dp" 右上方
android:bottomLeftRadius="20dp" 右下角
android:topLeftRadius="1dp" 左上方
android:bottomRightRadius="0dp" 左下角
/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
在 selector.xml 中 的 平常, 獲得焦點 , 按下時, 進行設定就可以看到不同的效果了
<selector
<item android:state_pressed="true" >
<shape>
</shape>
</item>
<item android:state_focused="true" >
<shape>
</shape>
</item>
</selector>
好了,也就這麼些了, 想看效果的話趕緊試試吧。。