设置Button背景渐变效果和点击效果
16lz
2022-01-02
1、设置背景渐变效果,在drawable目录下建buttonshape.xml文件,
内容为:
<?xml version="1.0" encoding="utf-8"?>
android:angle="270"/>
android:bottomRightRadius="10dip"
android:bottomLeftRadius="1dip"
android:topLeftRadius="18dip"
android:topRightRadius="10dip"/>
这里startColor是开始颜色,endColor是渐变结束颜色,默认是从上往下渐变,可以使用android:centerY调节,android:angle="270"设置角度。
corners设置边角的圆滑度。
设置点中的效果,在drawable目录下建buttonshape_down.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
android:shape="rectangle">
android:angle="270" />
android:bottomLeftRadius="1dip" android:topLeftRadius="18dip"
android:topRightRadius="10dip" />
在res目录下新建文件夹xml,然后在xml目录下,新建selectshape.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
- android:state_pressed="false"
android:drawable="@drawable/buttonshape" />
- android:state_pressed="true"
android:drawable="@drawable/buttonshape_down" />
- android:drawable="@drawable/buttonshape" android:state_window_focused="false"/> 是否获得焦点状态
设置了图片的触发状态,你可以设置 state_pressed,state_checked,state_pressed,state_selected,state_focused,state_enabled 等几个状态
state_pressed设置按钮状态,在main.xml文件中设置Button的属性:
android:bottomLeftRadius="1dip"
android:topLeftRadius="18dip"
android:topRightRadius="10dip"/>
android:topRightRadius="10dip" />
android:drawable="@drawable/buttonshape" />
android:drawable="@drawable/buttonshape_down" />
更多相关文章
- Android:退出程序后保持Serivce开启不关闭
- 浅谈android的selector背景选择器
- android中文字高亮设置案例
- Appium - Android(安卓)对比 iOS
- android中的selector背景选择器的用法
- Android:设置圆形头像,Android截取圆形图片
- 【安卓学习笔记】Android(安卓)Studio第9课——进度条ProgressBa
- Android(安卓)ListView 滑动背景为黑色的解决办法[转]
- Mac 下设置android NDK的环境