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 ...
随机推荐
- cocos2dx-Lua中出现的问题
1,在Lua中print输出失效的问题 在main.lua中添加print=release_print :
- c#3位一分(money)
NumberFormatInfo num = new NumberFormatInfo(); num.NumberDecimalDigits = 2; string ...
- mvc权限,登陆,异常
public class FilterOfPer : ActionFilterAttribute { public override void OnActionExecutin ...
- [转载]C#中播放背景音乐几种的方法
最经在写winform程序,其中有用到播放背景音乐 特此收集了一些网上的教程: 1.调用非托管的dll using System.Runtime.InteropServices; //DllImpor ...
- AxureRP制作Tab标签
1.添加动态Panel 2.双击进入编辑动态Panel 3.点击一个面板状态,编辑全部状态 4.选择虚线框,画出两个矩形图,一大一小:
- 支付宝Unity
原地址:http://blog.csdn.net/sgnyyy/article/details/20444627 说明:支付宝Android的SDK接入只有一个接口,付费. 1. Android代码的 ...
- php获取类的实例变量
<?php class Page {private $title; //构造函数固定名称为__construct,这样能将php的类构造函数独立于类名,以后修改类名就无需修改构造函数名称 fun ...
- Java将整个文件夹里的文本中的字符串替换成另外一个字符串(可用于项目复制,变成另一个项目)
import org.junit.Test; import java.io.*; /** * User: HYY * Date: 13-8-18 * Time: 下午8:11 * To change ...
- lsof命令总结
1.lsof 简介 lsof 是 linux 下的一个非常实用的系统级的监控.诊断工具.它的意思是 List Open Files,很容易你就记住了它是 “ls + of”的组合~它可以用来列出被各种 ...
- 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)
Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...