Android 自定义圆角按钮

Android 中自定义的控件经常要用到,下面是比较简单基础的。例子

res/drawable 目录下新建名为btn_bg.xml文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
<!--定义按钮的背景的颜色-->
    <solid android:color="#00CCFF"/>
    <!--设置按钮的每个角的弧度-->
    <corners android:radius="5dp"/>


    <!--按钮文字与边界的距离
	注意的地方,之前没有用到过-->
    <padding android:bottom="5dp"
             android:left="5dp"
             android:right="5dp"
             android:top="5dp"/>
</shape>



main.xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="圆角按钮"
            android:textSize="25dp"
            />
    <Button android:layout_width="match_parent"
            android:layout_height="80dp"
            android:background="@drawable/btn_bg"→背景图片引用
            android:text="自定义圆角按钮"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"


	    style="?android:attr/buttonStyleInset"/>
</LinearLayout>




扩展:
 style="?android:attr/buttonStyleInset"


@android:attr/button:普通按钮的效果
@android:attr/buttonBarButtonStyle:按钮栏的按钮效果
@android:attr/buttonBarStyle:按钮栏效果
@android:attr/buttonStyle:按钮的效果
@android:attr/buttonStyleInset:插入按钮的效果
@android:attr/buttonStyleSmall:小型按钮的效果
注:有些效果需要高级android SDK版本支持

@android:attr/buttonStyleToggle:选项按钮的效果


后续添加补充内容



源码地址:http://download.csdn.net/detail/csdnyuandaimaxuexi/9105529

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值