在应用程序,我一直在努力,我想有而不是两个了切换按钮提供。我试着开始我自己的扩展
按钮
,继 CompoundButton
来源,但坦白地说读了它的源有一个有点势不可挡。
In the app I've been working on, I would like to have a multiple-state (in my case, three) toggle button, instead of the two that ToggleButton
provides. I've tried to start my own that extends Button
, following the CompoundButton
source, but quite honestly reading over its source got a bit overwhelming.
有没有办法做到只使用一个选择XML或什么的,或者是另一种方法,我还没有想到一个三态切换按钮?我宁愿在如何做到这一点的损失。
Is there a way to do a three-state toggle button using just a selector xml or something, or perhaps another method I haven't thought of? I'm rather at a loss of how to do this.
您可以自定义一个选择作为背景,有三个条目使用。现在的问题是按钮的属性,你可以使用选择。您可以有两个布尔属性,比如说A和B,在A,B,和默认来定义选择。 (A和和B将满足A,所以更恰当,他们可以被认为是A,A和!和B,以及A和!&安培;!b)你可以重载现有属性(选择,有重点等),或者,更优雅,定义使用配方描述在这个线程自己的自定义属性。
You can certainly define a selector to use as a background that has three entries. The question is what button attributes you can use for the selector. You can have two boolean attributes, say A and B, and define the selector in terms of A, B, and default. (A && B will satisfy A, so more properly they could be thought of as A, !A && B, and !A && !B.) You can overload existing attributes (selected, focused, etc.) or, more elegantly, define your own custom attributes using the recipe described in this thread.