android自定义button样式
1,在drawable文件夹下定义button_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="#FFEC7600" /> <corners android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" android:topLeftRadius="5dip" android:topRightRadius="5dip" /> </shape> </item> <item android:bottom="1px" android:left="1px" android:right="1px" android:top="1px"> <shape> <gradient android:angle="90" android:centerX="0.5" android:centerY="0.5" android:endColor="#FFFED69E" android:startColor="#FFEC7600" android:type="linear" /> <corners android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" android:topLeftRadius="5dip" android:topRightRadius="5dip" /> </shape> </item> </layer-list>
2,定义button_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="#FFEC7600" /> <corners android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" android:topLeftRadius="5dip" android:topRightRadius="5dip" /> </shape> </item> <item android:bottom="1px" android:left="1px" android:right="1px" android:top="1px"> <shape> <gradient android:angle="90" android:centerX="0.5" android:centerY="0.5" android:endColor="#FFEC7600" android:startColor="#FFFED69E" android:type="linear" /> <corners android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" android:topLeftRadius="5dip" android:topRightRadius="5dip" /> </shape> </item> </layer-list>
3,定义按钮按下后的效果变化描述文件drawable/button.xml
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/button_default"/> </selector>
4,布局中引用:
android:background="@drawable/button"
转载:http://blog.csdn.net/lucherr/article/details/7476941
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28