自定义button的样式

本文介绍如何在Android Studio中使用XML定义Button的样式,包括不同状态下的背景颜色和边框效果,适用于希望提升应用UI设计质量的开发者。

Android studio中
1.这里写图片描述
这里写图片描述
在xml文件中添加如下代码

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
    <shape android:shape="rectangle">
        <corners android:radius="5px"></corners>
        <solid android:color="#46b5e9"></solid>
        <stroke android:color="#000"></stroke>
    </shape>
</item>
    <item android:state_pressed="false">
        <shape android:shape="rectangle">
            <corners android:radius="5px"></corners>
            <!--填充色-->
            <solid android:color="#46b5e9"></solid>
            <!--描边-->
            <stroke android:color="#000" android:width="5px"></stroke>
        </shape>
    </item>
</selector>

设置button的样式

<Button
                    android:id="@+id/fw_load_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:background="@drawable/load_button_style"
                    android:minHeight="0dp"
                    android:minWidth="0dp"
                    android:padding="10px"
                    android:text="下载附件"
                    android:textSize="55px" />

这里写图片描述

在eclipse中
res 下新建drawable —新建xml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值