Android学习之——实现圆角Button

在drawable文件夹下新建btn_shape.xml文件:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:shape="rectangle">
 4     <solid android:color="#ffffff"/>
 5     <corners
 6         android:topLeftRadius="8dip"
 7         android:topRightRadius="8dip
 8         android:bottomLeftRadius="8dip"
 9         android:bottomRightRadius="8dip"/>
10 </shape>

先解释一下上面的代码:

1.shape用于定义形状,有四种形状(矩形rectangle| 椭圆oval | 直线line | 圆形ring)。

2.solid用于设置填充形状的颜色。

3.corners用于创建圆角(只用于形状是矩形)。

topLeftRadius、topRightRadius、bottomLeftRadius、bottomRightRadius分别设置左上,右上,左下,右下圆角的半径。

使用方法:

android:background="@drawable/btn_shape"

1   <Button
2         android:layout_width="wrap_content"
3         android:layout_height="wrap_content"
4         android:id="@+id/button"
5         android:background="@drawable/btn_shape"
6         />

效果图:

1 参考网址:
2 http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
时间: 2024-08-05 15:54:06

Android学习之——实现圆角Button的相关文章

Android学习笔记-EditText&TextView&Button&菜单栏

界面文件activity_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="ma

Android学习笔记-EditText&amp;TextView&amp;Button&amp;菜单栏

界面文件activity_main.xml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/too

【Android学习笔记】圆角矩形ImageView自定义控件的实现与使用

在做安卓项目的过程中,我们总会遇到需要以圆角矩形控件来显示图标.图片或者按钮的需求,解决办法有两种,一种是在drawable下创建shape布局xml文件,另一种是自定义一个继承于ImageView的自定义控件类来实现,下面是具体的实现办法. 首先我们命名一个XCRoundRectImageView类,并继承于ImageView.代码如下: 1 import android.content.Context; 2 import android.graphics.Bitmap; 3 import a

Android开发学习笔记:圆角的Button

标签:Android Button 休闲 圆角 移动开发 在res目录下的drawable-mdpi建立xml文件shape.xml,如下图所示: shape.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectang

Android学习系列(17)--App列表之圆角ListView(续)

http://www.cnblogs.com/qianxudetianxia/archive/2011/09/19/2068760.html 本来这篇文章想并到上篇Android学习系列(16)--App列表之圆角ListView中的,但是若是如此就让大家错过一篇新的好的文章,着实可惜.上篇中我们使用shape,corners,gradient实现了一个渐变的圆角效果,但是在完文之后的实践中,我发现有时效果不甚满意,选中和放手的事件监听没有去正确的判断,然后渐变效果也比较单一,性能也觉得不是很快

[Android学习笔记]ListView中含有Button导致无法响应onItemClick回调的解决办法

转自:http://www.cnblogs.com/eyu8874521/archive/2012/10/17/2727882.html 问题描述: 当ListView的Item中的控件只是一些展示类控件时(比如TextView),注册ListView的监听setOnItemClickListener之后,当点击Item时候会触发onItemClick回调. 但是,当Item中存在Button(继承于Button)的控件时,onItemClick回调不会被触发. 解决方案: 在Item的布局文件

ndroid开发学习笔记:圆角的Button

转自:http://www.cnblogs.com/gzggyy/archive/2013/05/17/3083218.html 在res目录下的drawable-mdpi建立xml文件shape.xml,如下图所示: shape.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/andro

Android 自定义ImageView实现圆角/圆形 附加OnTouchListener详细注释以及Button圆角

转载请注明出处:王亟亟的大牛之路 平时要用一些非方方正正的按钮之类的小伙伴们是如何实现的?RadioButton?ImageButton?还是其他? 今天亟亟上的是ImageView来实现的 先上下效果图(目录结构) 分析: shape.xml用于Button的"倒角"(做过机械类的都懂,哈哈) attr.xml用于自定义ImageView的标签的定义 ids.xml用于控件findbyid用,为什么补+id 等会我会来解释 效果图: 分析:一个Button 2个自定义ImageVie

android自定义控件系列教程----真正的圆角button来了

前沿: 现在网上随便输入一句圆角button就会出现很多博客和文章提示做这样的一个效果,但是那多半都是xml文件来做的,这样做有个很大的弊端,因为每一次都需要重写xml文件(就连简简单单的修改个按钮的颜色也需要修改).~~为什么呢?因为不修改臣妾做不到啊!!!今天就带大家做一个真正的圆角button,我们还是来看效果吧. 正文干货开始: 很明显我们的按钮的背景就是我们要实现的圆角部分,那么我们情不自禁的想到了setBackground这个方法,看看里面的参数,需要的是一个Drawable,而我们