今天做了个按钮,不想麻烦美工做图片,又不喜欢方角的图片,就用xml做了圆角的图片,做好之后发现,点击的时候看不出点击效果了,xml可以定义点击效果,
就想怎么能两个一起实现,网上找了下大致看了一遍都不是我想要的,就慢慢的试了试,结果两者一结合就OK了。
1 <Button
2 android:id="@+id/repeat"
3 android:layout_width="fill_parent"
4 android:layout_height="wrap_content"
5 android:text="重新开始答题"
6 android:layout_marginLeft="10dip"
7 android:layout_marginRight="10dip"
8 android:layout_marginTop="25dip"
9 android:background="@drawable/button_style"
10 />
button_style如下:
1 <?xml version="1.0" encoding="utf-8"?>
2 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
3 <item android:state_pressed="true">
4 <shape xmlns:android="http://schemas.android.com/apk/res/android"
5 android:shape="rectangle">
6 <!-- 圆角深红色按钮 -->
7 <solid android:color="#4D0A0A"/>
8 <corners android:radius="8dip"/>
9 </shape>
10 </item>
11
12 <item android:state_pressed="false">
13 <shape xmlns:android="http://schemas.android.com/apk/res/android"
14 android:shape="rectangle">
15 <!-- 圆角红色按钮 -->
16 <solid android:color="#D9534F"/>
17 <corners android:radius="8dip"/>
18 </shape>
19 </item>
20
21 </selector>
button_style.xml是定义在drawable下的xml文件.
<corners android:radius="8dip"/> 定义圆角大小。