gpt4 book ai didi

android - 是否可以在同一个 button.xml 存档中定义具有背景可绘制行为的多个按钮?

转载 作者:行者123 更新时间:2023-11-30 02:27:36 25 4
gpt4 key购买 nike

这是我的第一篇文章。我的问题是下一个。我有几个带有个性化可绘制图像的按钮,我也想定义它们的行为。例如:

布局 xml:

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text"
android:background="@drawable/boton" />

可绘制的 boton.xml:

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

<item android:drawable="@drawable/btnanadir3"
android:state_pressed="true" />

<item android:drawable="@drawable/btnanadir2"
android:state_focused="true" />

<item android:drawable="@drawable/btnanadir1" />
</selector>

到现在为止没问题,但我想要 9 个这样的按钮,图像不同,我的问题是是否存在任何方法可以让所有按钮都在同一个 boton.xml 上,或者我必须让所有按钮在不同的 boton 中具有可绘制行为。每个xml?例如 boton.xml、boton2.xml、boton3.xml ... boton9.xml 以及包含 9 个 boton.xml 文件的可绘制文件夹?

谢谢

最佳答案

您将需要 9 个不同的 xml 文件,因为 xml 文件是指定图像的地方。

关于android - 是否可以在同一个 button.xml 存档中定义具有背景可绘制行为的多个按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27731951/

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