Android 中的圆形按钮
我想创建一个看起来与下面的完全一样的按钮背景(或按钮本身)。
我目前正在使用图像执行此操作。我尝试使用以下 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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,实体填充中间,描边绘制边框。由于您想要 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