圆角 + 边框 + 渐变 Button

在Drawable下创建文件:

bg_alibuybutton_default.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
	<item>
		<shape android:shape="rectangle">
			<solid android:color="@color/button_solid_color" />
			<corners android:topLeftRadius="5dip" 
			    android:topRightRadius="5dip"
				android:bottomLeftRadius="5dip" 
				android:bottomRightRadius="5dip" />
		</shape>
	</item>
	<item android:top="1px" 
	    android:bottom="1px" 
	    android:left="1px"
		android:right="1px">
		<shape>
			<gradient android:startColor="@color/button_defalut_start_color" 
			    android:endColor="@color/button_defalut_end_color"
				android:type="linear" 
				android:angle="90" 
				android:centerX="0.5"
				android:centerY="0.5" />
			<corners android:topLeftRadius="5dip" 
			    android:topRightRadius="5dip"
				android:bottomLeftRadius="5dip" 
				android:bottomRightRadius="5dip" />
		</shape>
	</item>
</layer-list>

bg_alibuybutton_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
	<item>
		<shape android:shape="rectangle">
			<solid android:color="@color/button_solid_color" />
			<corners android:topLeftRadius="5dip" 
			    android:topRightRadius="5dip"
				android:bottomLeftRadius="5dip" 
				android:bottomRightRadius="5dip" />
		</shape>
	</item>
	<item android:top="1px" 
	    android:bottom="1px"
	    android:left="1px"
		android:right="1px">
		<shape>
			<gradient android:startColor="@color/button_pressed_start_color" 
			    android:endColor="@color/button_pressed_end_color"
				android:type="linear" 
				android:angle="90" 
				android:centerX="0.5"
				android:centerY="0.5" />
			<corners android:topLeftRadius="5dip" 
			    android:topRightRadius="5dip"
				android:bottomLeftRadius="5dip"
			    android:bottomRightRadius="5dip" />
		</shape>
	</item>
</layer-list>

bg_alibuybutton_selected.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
	<item>
		<shape android:shape="rectangle">
			<solid android:color="@color/button_solid_color" />
			<corners android:topLeftRadius="5dip" 
			    android:topRightRadius="5dip"
				android:bottomLeftRadius="5dip" 
				android:bottomRightRadius="5dip" />
		</shape>
	</item>
	<item android:top="1px" 
	    android:bottom="1px" 
	    android:left="1px"
		android:right="1px">
		<shape>
			<gradient android:startColor="@color/button_selected_start_color" 
			    android:endColor="@color/button_selected_end_color"
				android:type="linear" 
				android:angle="90" 
				android:centerX="0.5"
				android:centerY="0.5" />
			<corners android:topLeftRadius="5dip" 
			    android:topRightRadius="5dip"
				android:bottomLeftRadius="5dip" 
				android:bottomRightRadius="5dip" />
		</shape>
	</item>
</layer-list>

bg_alibuybutton_states.xml

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
	<item android:state_pressed="true" android:drawable="@drawable/bg_alibuybutton_pressed" />
	<item android:state_focused="true" android:drawable="@drawable/bg_alibuybutton_selected" />
	<item android:drawable="@drawable/bg_alibuybutton_default" />
</selector>

 实际使用在Button的BackgroundDrawable引用最后的文件。

你可能感兴趣的:(button)