android实现按钮按下效果
1、定义两种不同样式的xml文件shape_color_primary.xml<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"><!--角度--><!--radius的值为控件高度的一半-->&l
·
1、定义两种不同样式的xml文件
shape_color_primary.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<!--角度-->
<!--radius的值为控件高度的一半-->
<corners
android:radius="15dp" />
<!--填充色-->
<solid
android:color="@color/blue"/>
</shape>
shape_border_color_primary.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--圆角的大小-->
<!--控件高度的一半-->
<corners android:radius="20dp"/>
<!--填充颜色-->
<!--@android中定义了一些颜色,可以自己查看使用-->
<solid android:color="@android:color/white"/>
<!--边框-->
<stroke
android:width="1dp"
android:color="@android:color/holo_blue_bright"/>
</shape>
2、定义选择器selector_color_primary.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/shape_border_color_primary"/>
<!--按钮默认状态-->
<item android:drawable="@drawable/shape_color_primary"/>
</selector>
3、通过控件的background属性引入,实现按钮按下效果
<Button
android:background="@drawable/selector_color_primary"
android:layout_width="wrap_content"
android:layout_height="40dp"/>
更多推荐
已为社区贡献5条内容
所有评论(0)