Android - 状态列表中有多个项目?
目前,我的应用程序中有一个键盘 0 - 9,我需要每个按钮都有打开和关闭状态。
为此,我使用了 StateList,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="@drawable/dialpad_1_off" />
<item android:state_pressed="true"
android:drawable="@drawable/dialpad_1_on" />
</selector>
但这仅适用于一个按钮,每个按钮都有不同的打开和关闭图形、dialpad_2_off、dialpad_3_on 等...
所以我是否必须为每个按钮创建一个 Statelist 或者有没有一种方法可以在一个 Statelist XML 文件中做到这一点?
I currently have a keypad in my application 0 - 9, I require an on and off state for each button.
To do this I've used a StateList as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="@drawable/dialpad_1_off" />
<item android:state_pressed="true"
android:drawable="@drawable/dialpad_1_on" />
</selector>
However this is only for one button, each button has a different on and off graphic, dialpad_2_off, dialpad_3_on etc...
So do I have to create a Statelist for every single button or is there a way to do it within one Statelist XML file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使图像的背景更改状态并为所有按钮使用通用背景。然后您可以使用文本或图像作为按钮前景。
You could make the background of the image change state and use that common background for all of the buttons. Then you could use either text or an image as the button foreground.