gpt4 book ai didi

java - 仅使用 xml 的带圆角的 ImageButton?

转载 作者:行者123 更新时间:2023-11-30 05:06:12 27 4
gpt4 key购买 nike

我正在尝试制作一个像这样的 ImageButton

this is the type of button I'm trying to replicate

但是,我似乎无法找到仅使用 xml 来完成此操作的方法。我尝试了自定义库,它们似乎无法完美运行。没有别的办法吗?除了使用 ImageButton,我还能做什么?

最佳答案

这是一个xml代码。

1.在您的 drawable 文件夹中创建一个 xml 文件,例如 button.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="3dp" />
<stroke android:width="1dp" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />
</shape>
</item>
</selector>

2.现在将此可绘制对象用作 View 的背景。如果 View 是按钮那么像这样:

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="#ffffff"
android:background="@drawable/mybutton"
android:text="Buttons" />

感谢 this answer

关于java - 仅使用 xml 的带圆角的 ImageButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54549336/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com