设置Button背景渐变效果和点击效果
16lz
2021-01-23
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" />
更多相关文章
- eclipse导入已存在的android工程时遇到AndroidManifest.xml文件
- Android中init.rc文件的解析
- Android中使用xml保存数据(xml文件序列化)及使用pull解析xml文件
- Android 文件读写操作方法总结
- 对android里布局文件当中的TextView对象设置事件监听,但是不响应
- 手动滑动TextView超出的内容
- Android解析xml文件
- android创建隐藏文件或者文件夹,并对其读写操作
- [基础知识]全面认识AndroidManifest.xml文件(二)