简体   繁体   English

Android - 状态列表中有多个项目?

[英]Android - Multiple items in a statelist?

I currently have a keypad in my application 0 - 9, I require an on and off state for each button.我目前在我的应用程序 0 - 9 中有一个键盘,我需要为每个按钮打开和关闭 state。

To do this I've used a StateList as follows:为此,我使用了 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>

However this is only for one button, each button has a different on and off graphic, dialpad_2_off, dialpad_3_on etc...然而,这仅适用于一个按钮,每个按钮都有不同的开关图形,dialpad_2_off,dialpad_3_on 等...

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?那么我是否必须为每个按钮创建一个 Statelist,或者有没有办法在一个 Statelist XML 文件中做到这一点?

You could make the background of the image change state and use that common background for all of the buttons.您可以更改图像的背景 state 并为所有按钮使用该公共背景。 Then you could use either text or an image as the button foreground.然后您可以使用文本或图像作为按钮前景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM