找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 42|回复: 0

Android里面,button按钮怎么设置圆角?

[复制链接]

2万

主题

134

回帖

13万

积分

管理员

积分
134018
发表于 2024-7-26 21:07:13 | 显示全部楼层 |阅读模式 IP:山东省青岛市 联通

登录后更精彩...O(∩_∩)O...

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Android里面,button按钮怎么设置圆角?

在Android中,可以通过创建一个自定义的Drawable XML文件来实现给Button设置圆角的效果。以下是创建圆角按钮的步骤:

  • 在 res/drawable 文件夹下,创建一个新的XML文件,例如 rounded_button.xml。

  • 在 rounded_button.xml 文件中,添加以下代码:



[XML] 纯文本查看 复制代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="8dp" />
            <solid android:color="@color/your_button_color" />
            <stroke android:width="2dp" android:color="@color/your_stroke_color" />
        </shape>
    </item>
</selector>


  • 在这里,你可以自定义圆角的半径、按钮的颜色和边框颜色。例如,可以将 android:radius 的值设置为你需要的圆角半径,将 android:color 的值设置为你需要的按钮颜色。

  • 接下来,将 rounded_button.xml 设置为 Button 的背景。在你的布局XML文件中,找到你想设置圆角的Button,然后添加 android:background 属性,如下所示:

[Java] 纯文本查看 复制代码
<Button
    android:id="@+id/my_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click me"
    android:background="@drawable/rounded_button" />



现在,你的Button应该具有圆角效果了。请注意,你可能需要根据你的需求调整其他Button属性,例如 android:textSize、android:textColor 等。


from: Android里面,button按钮怎么设置圆角?_android button圆角-CSDN博客
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|时间戳|加密|CTF WiKi|CTF平台汇总|CTF show|ctfhub|棱角安全|rutracker|攻防世界|php手册|peiqi文库|CyberChef|猫捉鱼铃|手机版|小黑屋|cn-sec|IOTsec-Zone|在线工具|分享屋 ( 鲁ICP备2021028754号 )

GMT+8, 2024-9-8 11:59

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表