Android 不提供任何双态切换按钮?
Android doesn't provide any two-State toggle buttons?
我对使用 Android 有点陌生,当我研究一些 android 按钮功能时,我意识到开关或切换器的实现方式与我预期的不同。我看到 ToggleButton
如果您单击按钮,文本会更改。对于 Switch
,我看到没有文字,但您可以向左或向右滑动开关以显示某种 "on/off" 功能。理想情况下,我想要一个双态切换,类似于这张照片:
但我似乎找不到某种可以为我执行此操作的切换按钮。 Switch
没有文本,ToggleButton
有文本,但只有一个 "state" 正在显示。我试图查看其他类似 https://github.com/jlhonora/multistatetogglebutton 的内容,但这更适用于多个状态:我只希望切换按钮中有 2 个状态。任何帮助,将不胜感激。谢谢!
Switch
就是你想要的。
In the documentation you can find how to change the text
Sets the text displayed when the button is not in the checked state.
Sets the text displayed when the button is in the checked state.
Java:
void setTextOff(CharSequence textOff)
void setTextOn(CharSequence textOn)
XML:
android:textOff
android:textOn
在 android 5.0 及更高版本中,它不显示打开和关闭的文本。您必须在 xml 中指定它们,例如 android: textOff 和 android: textOn。
我对使用 Android 有点陌生,当我研究一些 android 按钮功能时,我意识到开关或切换器的实现方式与我预期的不同。我看到 ToggleButton
如果您单击按钮,文本会更改。对于 Switch
,我看到没有文字,但您可以向左或向右滑动开关以显示某种 "on/off" 功能。理想情况下,我想要一个双态切换,类似于这张照片:
但我似乎找不到某种可以为我执行此操作的切换按钮。 Switch
没有文本,ToggleButton
有文本,但只有一个 "state" 正在显示。我试图查看其他类似 https://github.com/jlhonora/multistatetogglebutton 的内容,但这更适用于多个状态:我只希望切换按钮中有 2 个状态。任何帮助,将不胜感激。谢谢!
Switch
就是你想要的。
In the documentation you can find how to change the text
Sets the text displayed when the button is not in the checked state.
Sets the text displayed when the button is in the checked state.
Java:
void setTextOff(CharSequence textOff)
void setTextOn(CharSequence textOn)
XML:
android:textOff
android:textOn
在 android 5.0 及更高版本中,它不显示打开和关闭的文本。您必须在 xml 中指定它们,例如 android: textOff 和 android: textOn。