android把任何可绘制在屏幕上的图形图像都称为drawable.
XML drawable与像素密度无关,将其放入drawable目录即可。
一、shape drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="3dp"/> <gradient android:angle="270" android:endColor="#cccccc" android:startColor="#acacac"/> </shape>二、state list drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_shape_normal" android:state_pressed="false"/> <item android:drawable="@drawable/button_shape_pressed" android:state_pressed="true"/> </selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="#ffffff" android:state_pressed="false"/> <item android:color="#556699" android:state_pressed="true"/> </selector>三、layer list 与 inset drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <corners android:radius="5dp"/> <gradient android:angle="90" android:centerColor="#303339" android:centerY="0.05" android:endColor="#000000" android:startColor="#000000"/> </shape> </item> <item> <inset android:drawable="@drawable/button_shape" android:insetBottom="5dp"/> </item> </layer-list>效果:出现阴影