1,在drawable文件夹下定义button_default.xml:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#FFEC7600" /> <corners android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" android:topLeftRadius="5dip" android:topRightRadius="5dip" /> </shape> </item> <item android:bottom="1px" android:left="1px" android:right="1px" android:top="1px"> <shape> <gradient android:angle="90" android:centerX="0.5" android:centerY="0.5" android:endColor="#FFFED69E" android:startColor="#FFEC7600" android:type="linear" /> <corners android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" android:topLeftRadius="5dip" android:topRightRadius="5dip" /> </shape> </item> </layer-list>
2,定义button_pressed.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#FFEC7600" /> <corners android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" android:topLeftRadius="5dip" android:topRightRadius="5dip" /> </shape> </item> <item android:bottom="1px" android:left="1px" android:right="1px" android:top="1px"> <shape> <gradient android:angle="90" android:centerX="0.5" android:centerY="0.5" android:endColor="#FFEC7600" android:startColor="#FFFED69E" android:type="linear" /> <corners android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" android:topLeftRadius="5dip" android:topRightRadius="5dip" /> </shape> </item> </layer-list>
3,定义按钮按下后的效果变化描述文件drawable/button.xml
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/button_default"/> </selector>
4,布局中引用:
android:background="@drawable/button"
转载:http://blog.csdn.net/lucherr/article/details/7476941
相关推荐
Android自定义Button的通用方法
android studio 自定义button边框,角度,渐变颜色按下时改变样式, 以及基础动画,为image view添加旋转,下移,渐变等样式,使用timer handler button进行控制。
android 自定义各种风格button
安卓 android 自定义 switch button,滑动开关,绝对漂亮美观
NULL 博文链接:https://2528.iteye.com/blog/1164340
如何自定义CheckBox的样式 1:首先在布局文件中添加CheckBox的控件配置,如: android:id="@+id/button1" style="@style/CheckBoxStyles"//这里就是用户可以自定CheckBox的样式 android:layout_width="match_...
* ,通常我们需要自定义Button样式,自定义Button样式有三种: * 1、使用.9格式图片作为Button背景,或者作为ImageView、 * TextView、RadioButton等控件背景,效果都不错,能够自适应 * 2、使用自定义矢量图的...
NULL 博文链接:https://chennaigong.iteye.com/blog/1143049
使用新的方法实现Button效果,如上图一样,有时候我们需要一个Button,前面有一个小型的图标,有两种办法,可以自定义一个Button,其实,我们不必纠结于Button这个词,只要能获得点击事件,做出Button一样的效果就可以
Button 自定义点击样式,添加音效 http://blog.csdn.net/shark0017
一、shape 样式:(在drawable新建–》new–》Drawable resource file 在父级标签selector添加Item ) <?xml version=1.0 encoding=utf-8?> <selector xmlns:android=...
自定义了一下Button的样式 需要的朋友可以拿去看一下效果
最近在开发一个WIFI连接的功能,点击WIFI需要弹出自定义密码输入框。在此权当记录 效果图 点击首页的Button即跳出对话框,显示WIFI信息(TextView),密码输入框(EditText),取消和连接按钮(Button) 实现 根据自己实际的...
Android Studio 在xml文件中设置界面布局1、xml文件中给输入框editText修改下划线颜色2、设置button按钮为圆角及修改按钮颜色3、运用约束布局时预览效果和运行效果不一致 写一写今天困扰我很久的问题:如何给...
先上图,看看接下来我要向大家介绍的是个什么东西,如下图: ...首先button自己有background和src,如果把半透明的水波纹当作background或者src绘制到button上面,肯定是会损失button原有的样式的。可能有朋友猜想那就
在高德地图中点击弹出自定义弹框(气泡)。(结合上一个上传的文件,也可用于标记点的点击弹出的弹框气泡)
Android自定义View研究-- 一个小Demo Android调用相册拍照实现系统控件缩放切割图片 Android SQLite的实例汇总大全 两分钟彻底让你明白Android Activity生命周期(图文)! Android 图形系统剖析 Android 立体效果图片...
CheckBox是Android中用的比较多的一个控件,不过它自带的button样式比较丑,通常都会替换成本地的资源图片。使用本地资源图片很简单,设置android:button属性为一个自定义的包含selector的drawable文件即可。 例如...
Button是Android中一个非常简单的控件,在我们平时的项目中,可以说是非常的常见,使用率也是相当高。下面通过实例代码给大家介绍Android studio button 按钮 四种绑定事件的方法,具体代码如下所示: package ...
5.2.5 使用按钮——Button 5.2.6实例——计算器 5.2.7 使用图片按钮——ImageButton 5.2.8 使用复选框——CheckBox 5.2.9实例——请同意本协议 5.2.10 使用单选框——RadioGroup 5.2.11 实例——请选择性别 5.2.12...