gpt4 book ai didi

android - 多状态切换按钮

转载 作者:IT王子 更新时间:2023-10-28 23:28:55 28 4
gpt4 key购买 nike

在我一直在开发的应用程序中,我希望有一个多状态(在我的例子中是三个)切换按钮,而不是 ToggleButton 提供的两个。我尝试开始自己的扩展 Button,遵循 CompoundButton 源代码,但老实说,阅读它的源代码有点不知所措。

有没有办法只使用选择器 xml 或其他东西来实现三态切换按钮,或者可能是我没有想到的另一种方法?我不知道如何做到这一点。

最佳答案

我实现了一个多状态切换按钮,源代码是here

看起来是这样的:

enter image description here

而且使用起来非常简单:

<org.honorato.multistatetogglebutton.MultiStateToggleButton
android:id="@+id/mstb_multi_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
mstb:values="@array/planets_array" />

在你的 Activity 中:

MultiStateToggleButton button2 = (MultiStateToggleButton) this.findViewById(R.id.mstb_multi_id);
button2.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() {
@Override
public void onValueChanged(int value) {
Log.d(TAG, "Value: " + value);
}
});

关于android - 多状态切换按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4823851/

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