这样的button样式应该源自IOS。假设安卓上实现,则须要使用android上面的layer-list来实现。

事实上layer-list有点像framlayout,作用就是覆盖。


先说一下实现原理:先画一个矩形。就是我们所示红色边框。

然后再画一个矩形将白色背景覆盖上面,设置android:left | right | top |bottom值。能够实现边框的大小。

然后在button里面设置background属性就好了,以下附上源代码。


由于三个button形状都不一样,所以要设置三个layer—list。

他们当中的差别也仅仅是Radius的差别。


假设须要设置比方三选一,而且有按下效果的话。最好使用RadioButton来实现。然后在drawable里面再实现<Selector>就能够了。
<div style="text-align: left;"><pre name="code" class="html"><?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 连框颜色值 -->
<item>
<shape>
<solid android:color="#ff0000" /> //背景填充红色 <corners
android:bottomRightRadius="4dp" //设置圆角
android:topRightRadius="4dp" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item
android:bottom="1dp" //边框的宽度
android:right="1dp"
android:top="1dp">
<shape>
<solid android:color="#ffffff" /> <corners
android:bottomRightRadius="4dp"
android:topRightRadius="4dp" /> <padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item> </layer-list>


<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_centerHorizontal="true"
android:background="@drawable/button_mid" <span style="font-family: Arial, Helvetica, sans-serif;">//设置button的形状</span> android:text="Button3" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/button3"
android:background="@drawable/button_right" //设置button的形状
android:text="Button2" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="110dp"
android:layout_toLeftOf="@+id/button3"
android:background="@drawable/button_left" <span style="font-family: Arial, Helvetica, sans-serif;">//设置button的形状</span>
android:text="Button1" /> </RelativeLayout>


android_重写button样式的更多相关文章

  1. WPF重写Button样式

    首先指定OverridesDefaultStyle属性为True: 然后添加样式: 重写ControlTemplate: <Window.Resources> <Style x:Ke ...

  2. 重写 button 的创建方法

    重写 button 的创建方法 //sxc时时改变 // self.videoM.progress = progress; // if ([self.videoM.downloadStr isEqua ...

  3. 【译文】CSS技术:如何正确的塑造button样式!

    , but useful for */ display: inline-block; text-align: center; text-decoration: none; /* create a sm ...

  4. 36种漂亮的CSS3网页按钮Button样式

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  5. android中样式和自定义button样式

    1)自定义button样式 一.采用图片方式 首先新建Android XML文件,类型选Drawable,根结点选selector,自定义一个文件名. 随后,开发环境自动在新建的文件里加了select ...

  6. wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合

    wpf 导出Excel   1 private void Button_Click_1(object sender, RoutedEventArgs e) 2 { 3 4 ExportDataGrid ...

  7. CSS开发技巧(一):button样式设置

    button样式需要注意的有几点: 1.建议有一个最小宽度,以免在文字很少时使得按钮过于窄,宽高不协调: 2.建议有一个padding,以免内部文本显得过于拥挤: 2.hover时需要有颜色变化,以告 ...

  8. swift 定制自己的Button样式

    swift的UIButton类中有些公开方法可以重写,所以,如果想写出自己的UIButton,只要继承UIButton类,并重写相应的方法即可. 系统的UIButton可以添加图片,也可以添加标题,但 ...

  9. UWP 改变Button样式

    -----some words------ 1.Control:控制 (我们理解成控件) 2.Template:模板 3.Ellipse 椭圆 4.Content 内容 5.Presenter 节目主 ...

随机推荐

  1. Ace of Aces

    Description There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the ...

  2. 让Delphi XE2程序支持UAC

    在win7下,开发的程序有的时候莫名其妙就不能正常工作了,其实都是因为权限不够,要想能够正常运行,就需要获得管理员权限,这就需要处理UAC.具体方法如下: 一,制作“uac.manifest”文件.新 ...

  3. TCP的三次握手和四次挥手(转)

    注:主动.被动 与 服务器.客户端没有明确的对应关系. 这个图N多人都知道,它排除和定位网络或系统故障时大有帮助,但是怎样牢牢地将这张图刻在脑中呢?那么你就一定要对这张图的每一个状态,及转换的过程有深 ...

  4. 7个基于Linux命令行的文件下载和网站浏览工具

    7个基于Linux命令行的文件下载和网站浏览工具 时间:2015-06-01 09:36来源:linux.cn 编辑:linux.cn 点击: 2282 次 Linux命令行是GNU/Linux中最神 ...

  5. 【Demo 0007】Java基础-类扩展特性

    本章学习要点:        1.  掌握static 修饰的类,方法以及变量的功能及用法;        2.  掌握代码块(静态,非静态)的作用以及注意事项:        3.  了解基本数据类 ...

  6. LIS问题分析

    题目来源,待字闺中,原创@陈利人 ,欢迎大家继续关注微信公众账号"待字闺中" 原题这个LIS问题,可不是Longest Increasing Subsequence,而是Large ...

  7. Python 学习入门(23)—— 进程

    本文介绍Python的os包中有查询和修改进程信息的函数,Python的这些工具符合Linux系统的相关概念,所以可以帮助理解Linux体系. 1. 进程信息 os包中相关函数如下: uname()  ...

  8. uva 1335 - Beijing Guards(二分)

    题目链接:uva 1335 - Beijing Guards 题目大意:有n个人为成一个圈,其中第i个人想要r[i]种不同的礼物,相邻的两个人可以聊天,炫耀自己的礼物.如果两个相邻的人拥有同一种礼物, ...

  9. 终于懂了:Delphi消息的Result域出现的原因——要代替回调函数的返回值!(MakeObjectInstance不会帮助处理(接收)消息回调函数的返回值)

    MakeObjectInstance应该不会帮助处理(接收)消息回调函数的返回值,可是有时候又确实需要这个返回值,这可怎么办呢?我是看到这段文字的时候,想到这个问题的: 当WM_PAINT不是由Inv ...

  10. MySQL 存储过程例子,不能在if else里面用begin end否则会报错Error Code : 1064!

    Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your My ...