安卓APP按键美化——圆角按键

一、新建按钮样式文件

  • 正常状态
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- 圆角的半径 -->
    <corners android:radius="30dp"/>

    <!-- 填充颜色 -->
    <solid android:color="#00ff00"/>

</shape>

  • 按下状态
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- 圆角的半径 -->
    <corners android:radius="30dp"/>

    <!-- 填充颜色 -->
    <solid android:color="#0662f5"/>

</shape>

二、新建样式文件

定义按钮的不同状态样式,btn_selector
btn_normal(正常),btn_pressed(按下)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- 正常状态 -->
    <item android:drawable="@drawable/btn_normal" android:state_pressed="false"/>

    <!-- 按下状态 -->
    <item android:drawable="@drawable/btn_pressed" android:state_pressed="true"/>

</selector>


三、使用按钮样式

android:background="@drawable/btn_selector"

四、结合前面知识,制作一个简单界面

正常状态
在这里插入图片描述

按下状态
在这里插入图片描述

代码

<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:background="@drawable/bg_shopping_menu"
    tools:context=".MainActivity" >
    
    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00ff00"
        >
        
      	<TextView 
      	    android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="刷卡机"
            android:textSize="25dp"
            android:layout_marginTop="4dp"
            android:layout_marginLeft="10dp"
      	    />
        
      	
        <Button 
            android:id="@+id/zc1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册"
            android:layout_alignParentRight="true"
            android:layout_marginRight="15dp"
            />

        <Button 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="查询信息"
            android:layout_toLeftOf="@id/zc1"
            android:layout_marginRight="15dp"
            />
        
    </RelativeLayout>
    
    <ImageView 
        android:id="@+id/k1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/pic_rf"
        android:layout_centerInParent="true"
        />
    
    <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/card"
        android:layout_centerInParent="true"
        android:paddingLeft="120dp"
        />
    
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="刷卡"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="50dp"
        android:background="@drawable/btn_selector"
        />
    
</RelativeLayout>

师承上官可编程 —— 陈立臣

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dz小伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值