Button 自定义(一)-shape
需求:自定义Button,使用系统自定义Shape;
效果图:
1.默认状态

2.选中状态

实现分析:
1.目录结构:

代码实现:
1.button_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#ff007aff" /> <corners
android:bottomLeftRadius="6dp"
android:bottomRightRadius="6dp"
android:topLeftRadius="6dp"
android:topRightRadius="6dp" /> </shape>
2.button_select.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFD700" /> <corners
android:bottomLeftRadius="6dp"
android:bottomRightRadius="6dp"
android:topLeftRadius="6dp"
android:topRightRadius="6dp" /> </shape>
solid:实心,就是填充的意思
corners:圆角
android:radius为角的弧度,值越大角越圆。
3.button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_select" android:state_focused="true"></item>
<item android:drawable="@drawable/button_select" android:state_pressed="true"></item>
<item android:drawable="@drawable/button_normal" android:state_focused="false" android:state_pressed="false"></item>
<item android:drawable="@drawable/button_normal" ></item> </selector>
4.fragment_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jjc.demo.MainActivity$PlaceholderFragment" > <Button
android:id="@+id/button_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_selector"
android:text="推荐组合"
android:textColor="@android:color/white" /> </RelativeLayout>
代码:http://pan.baidu.com/s/1ntBN5Df
Button 自定义(一)-shape的更多相关文章
- android 自定义Button,抛弃写shape文件
标签: android 控件 自定义 2017年05月27日 17:52:13 611人阅读 评论(0) 收藏 举报 分类: 自定义View(2) 作者同类文章 X 版权声明:本文为博主原创文章 ...
- Android-----使用Button特效 selector+shape
当然除了使用drawable这样的图片外今天谈下自定义图形shape的方法,对于Button控件Android上支持以下几种属性shape.gradient.stroke.corners等. 我们就以 ...
- Android自定义图形shape
在Android开发过程中,经常需要改变控件的默认样式, 那么通常会使用多个图片来解决.不过这种方式可能需要多个图片,比如一个按钮,需要点击时的式样图片,默认的式样图片. 这样就容易使apk变大.另一 ...
- Android自定义drawable(Shape)详解
在Android开发过程中,经常需要改变控件的默认样式, 那么通常会使用多个图片来解决.不过这种方式可能需要多个图片,比如一个按钮,需要点击时的式样图片,默认的式样图片. 这样就容易使apk变大. 那 ...
- 18 UI美化自定义形状shape
自定义某个控件的形状 如 圆角 巨型 环形 : 在工程文件的新建 res/drawable/shape文件(以下键一个圆角) <?xml version="1.0" enco ...
- Button 自定义图片,代码绘制样式,添加音效的方法
Button自己在xml文件中绑定监听器 <!-- 设定onclick属性,然后在activity中定义相应的方法 --> <!-- 通过xml布局中通过button的android ...
- Android之Button自定义点击效果
我们在界面上经常会用到button按钮,但通常button点击后看不到点击的效果,如果用户连续点击了两次,就会报NAR错误,这样交互性就比较差了.如果我们自定义了button点击效果,比如我们点击了b ...
- [WPF系列]Button 自定义
A Simple Cross Button for WPF CREATING MORE COMPLEX BUTTONS IN XAML WPF Custom Controls - Withou ...
- Android之用自定义的shape去实现shadow效果
直接上xml文件, 并且附上相应的解析: <?xml version="1.0" encoding="utf-8"?> <selector x ...
随机推荐
- oracle 将科学计数法数据转换为非科学计数法数据
oracle 自定义函数: CREATE OR REPLACE FUNCTION ConvertNumeric(rawData VARCHAR2) --用于返回转换科学计算法dhx RETURN VA ...
- 【BZOJ2049】 [Sdoi2008]Cave 洞穴勘测
Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...
- angularApi网站用vue重构
最近在博客园上看到不少关于vue的文章但感觉都是在简单原生写法上,真正vue在实际开发中的优点组件化,spa应用,路由好像都没涉及到,我在学angular1的时候发现没有中文版的api,于是本人不才弄 ...
- 浅淡Windows7 32位与64位/x86与x64的区别
看到有很多会员问到底是选Windows7 x86,还是选x64.这里简单的谈一下这这两种系统的区别. 简单的说x86代表32位操作系统 x64代表64位操作系统. 简单的判断电脑是否支持64位操作系 ...
- eval()字符串转成对象
var s = "{a:1,b:2}"; console.log(typeof s); s = eval("(" + s + ")"); c ...
- Binary search for the first element greater than target
We all know how to search through an array for an element whose value equals the target value, but h ...
- 团体程序设计天梯赛-练习集L1-023. 输出GPLT
L1-023. 输出GPLT 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个长度不超过10000的.仅由英文字母构成的 ...
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Pokemon Master
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3776 题意:比较两组数据的总和大小. #include <iostr ...
- Scala中的Extractor
Scala中使用unapply方法可以实现三种extractor(另外使用unapplySeq也可以实现extractor) def unapply(object: S): Option[(T1, . ...
- request重定向或者是response转发请求后面的代码依然执行
调用response.redirect(),或者request.getRequestDispatcher(loginAddr).forward(request,response);后,后面的代码照样执 ...