点击button,button背景图片变化
1、设置背景渐变效果,在drawable目录下建buttonshape.xml文件,
内容为:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#01DFD7" android:endColor="#81F7F3"
android:angle="270"/>
<corners
android:bottomRightRadius="10dip"
android:bottomLeftRadius="1dip"
android:topLeftRadius="18dip"
android:topRightRadius="10dip"/>
</shape>
这里startColor是开始颜色,endColor是渐变结束颜色,默认是从上往下渐变,可以使用android:centerY调节,android:angle="270"设置角度。
corners设置边角的圆滑度。
设置点中的效果,在drawable目录下建buttonshape_down.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#F5F510" android:endColor="#F5F5B0"
android:angle="270" />
<corners android:bottomRightRadius="10dip"
android:bottomLeftRadius="1dip" android:topLeftRadius="18dip"
android:topRightRadius="10dip" />
</shape>
在res目录下新建文件夹xml,然后在xml目录下,新建selectshape.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false"
android:drawable="@drawable/buttonshape" />
<item
android:state_pressed="true"
android:drawable="@drawable/buttonshape_down" />
<item
android:drawable="@drawable/buttonshape" android:state_window_focused="false"/> 是否获得焦点状态
</selector>设置了图片的触发状态,你可以设置 state_pressed,state_checked,state_pressed,state_selected,state_focused,state_enabled 等几个状态
state_pressed设置按钮状态,在main.xml文件中设置Button的属性:
<Button android:id="@+id/button_reimbursementrecords"
android:text="报销记录" android:layout_width="280px"
android:layout_height="80px" android:textSize="30px"
android:background="@xml/selcetshape" />
使用background设置按钮的背景色。
点击button,button背景图片变化的更多相关文章
- WPF之路二: button添加背景图片点击后图片闪烁问题
在为button添加背景图片的时候,点击后发现图片闪烁,我们仔细观察,其实Button不仅仅只是在点击后会闪烁,在其通过点击或按Tab键获得焦点后都会闪烁,而通过点击其他按钮或通过按Tab键让Butt ...
- WPF Button的背景图片设置
这个问题很简单,但是对于从winfrom转过来的来讲,在做事的时候就会被绕进去,言归正传,如何设置一个bUtton的背景图片?如何去掉让人烦的默认选中时的灰色背景?请看如下的描述.问题的来源和解决都在 ...
- 【转】UGUI之用脚本动态的改变Button的背景图片 和 颜色
http://blog.csdn.net/u014771617/article/details/45102701 public Button button;void Start(){ColorBloc ...
- C#(winform)为button添加背景图片,并去掉各种边框
1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = "" ;来设置图片 而不应该使用 Button.Image = "" ...
- C#(winform)为button添加背景图片
1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = "" ;来设置图片 而不应该使用 Button.Image = "" ...
- 【android开发笔记】为Button的背景图片添加边框式样式效果
现在做的项目遇到一个问题,设计给过来的图片只有一种状态,但是实现的需求是要求有两个状态,另一种选状态为图片背景加边框.如图: 刚开使用使用ImageView ,ImageViewButton 效果不是 ...
- WPF学习笔记——为BUTTON添加背景图片
首先要肯定,代码: <Style x:Key="UserItemButton" TargetType="Button"> <Setter Pr ...
- ios UIButton 选中后背景图片变化发灰问题
UIButton的类型如果选择了System类型,那么设置背景图后,点击的效果是图片发灰,而不是默认的那种图片变淡黑色效果,需要用customer类型就好了.
- js实现点击切换checkbox背景图片
在制作网页的过程中,经常需要实现点击切换背景图片的效果,本文关注的是表单中checkbox背景图片切换的实现.如图,在输入用户名和密码后,用户需要选择是否记住密码 图片背景为白色表示未勾选状态 ,背景 ...
随机推荐
- kubernetes deployment
deployment是k8s中部署应用最常见的一种方式.如果不需要被访问,那么只需要定义deployment即可.如果需要被其他服务访问,那么可以创建一个service与其绑定,通过访问service ...
- /dev/sdxx is apparently in use by the system; will not make a filesystem here! 解决方法
在存储上共享了一个500G的空间,映射到Linux系统提供上,环境由2个节点组成. 一. 测试一: 直接mount 用fdisk 格式化之后如下: [root@rac1 u01]# fdisk -l ...
- CodeIgniter(3.1.4)框架中成功/错误跳转
if ( ! function_exists('error')) { /** * 错误跳转 */ function error($mes, $url) { echo '<script type= ...
- CodeIgniter(3.1.4)框架中-使用多个公共控制器
项目目录结构: 在core/MY_Controller.php文件下: <?php /** * Class MY_Controller * 自定义控制器 */ class MY_Controll ...
- Applet Mode
https://github.com/threerings/getdown/wiki/Applet-Mode ————————————————————————————————————————————— ...
- 微信小程序——获取绑定事件元素的ID
小程序list数据带值跳转,一般直接通过设置item的id来标识或者通过设置键值data-xxxx的方式标识.如下图所示: 解析出来的结果如下图: 我们看到它在元素上绑定了一个checkSchoolL ...
- [从jQuery看JavaScript]-注释(comments)
jQuery片段: /*! * jQuery JavaScript Library v1.3.2 * http://jquery.com/ * * Copyright (c) 2009 John Re ...
- 逻辑斯特回归(logistic regression)的迭代变权最小平方差算法(IRLS)
参考资料:http://blog.csdn.net/xuanyuansen/article/details/41050507 习题: 数据及代码: https://pan.baidu.com/s/1 ...
- e686. 显示打印窗口
The print dialog allows the user to change the default printer settings such as the default printer, ...
- e666. 创建缓冲图像
A buffered image is a type of image whose pixels can be modified. For example, you can draw on a buf ...