有关Button、ImageView、ImageButton、TextView等组件都可以设置它们的按下效果,有两种解决方案,一是在代码里面写,二是在xml中写,个人偏向于在xml写。
一:在xml中,可以用selector完成,例如:
一个Button平时状态:按下的状态:
在drawable中新建一个xml文件:shape_common_radiusbtn,控制背景色
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<selector xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item android:state_pressed=
"true"
>
<shape>
<corners android:radius=
"5dp"
/>
<padding android:bottom=
"1dp"
android:left=
"1dp"
android:right=
"1dp"
android:top=
"1dp"
/>
<stroke android:width=
"1dp"
android:color=
"@color/text_brown_d7c093"
/>
<solid android:color=
"@color/text_brown_d7c093"
/>
</shape></item>
<item>
<shape>
<corners android:radius=
"5dp"
/>
<padding android:bottom=
"1dp"
android:left=
"1dp"
android:right=
"1dp"
android:top=
"1dp"
/>
<stroke android:width=
"1dp"
android:color=
"@color/text_brown_d7c093"
/>
<solid android:color=
"@color/white"
/>
|