Android按钮美化
下面介绍的Android按钮的美化主要是通过android:background来实现的。
一、首先需要定义按钮样式
在res/drawable下新建文件button_selector.xml,内容如下
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- pressed --> <item android:state_pressed="true" > <shape android:shape="rectangle"> <gradient android:startColor="#ff2b35f0" android:endColor="#ff2b35f0" android:angle="270" /> <corners android:radius="4dp" /> </shape> </item> <!-- focus --> <item android:state_focused="true" > <shape> <gradient android:startColor="#ffc2b7" android:endColor="#ffc2b7" android:angle="270" /> <corners android:radius="4dp" /> </shape> </item> <!-- default --> <item> <shape> <gradient android:startColor="#ff00aced" android:endColor="#ff00aced" android:angle="0" /> <corners android:radius="4dp" /> </shape> </item> </selector>
二、使用美化的按钮
在原有Button布局文件上增加android:background="@drawable/button_selector"
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/subscribe" android:id="@+id/buttonSubscribe" android:layout_gravity="center_horizontal" android:background="@drawable/button_selector" />
效果如下:
相关推荐
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