Android 中的圆形按钮

发布于 2025-01-03 03:04:09 字数 545 浏览 2 评论 0原文

我想创建一个看起来与下面的完全一样的按钮背景(或按钮本身)。

在此处输入图像描述

我目前正在使用图像执行此操作。我尝试使用以下 XML 创建一个类似的文件,但它看起来并不符合预期。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="oval">
   <solid
     android:color="#f0600000"/>
   <stroke
     android:width="10dp"
     android:color="#FFFF6666"/>
</shape>

实际上我想要一个带有 3 像素阴影和 1/4 宽度描边的圆形按钮,白色圆圈周围为红色。阴影部分我根本没有成功。感谢您的任何帮助。

I want to create a button background (or button itself) that look exactly like the below one.

enter image description here

I'm doing it currently with an image. I tried to create a similar one using the following XML, but it doesn't look as expected.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="oval">
   <solid
     android:color="#f0600000"/>
   <stroke
     android:width="10dp"
     android:color="#FFFF6666"/>
</shape>

Actually I want a round button with 3 pixel shadow and 1/4 width stroke in red color around the white circle. I have not succeeded with the shadow part at all. Thanks for any sort of help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情仇皆在手 2025-01-10 03:04:09

好吧,实体填充中间,描边绘制边框。由于您想要 3 种颜色,因此必须使用 2 个可绘制对象,在带有灰色边框的红色圆圈上绘制白色圆圈。然后,您可以使用 LayerDrawable 将它们保持为一个单元

Well, the solid fills the middle and stroke paints the border. Since you want 3 colors you will have to use 2 drawables, painting white circle over the red circle with grey border. You can then use LayerDrawable to keep these as one unit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文