<分区>
我对使用 Android 有点陌生,当我研究一些 android 按钮功能时,我意识到开关或切换器的实现方式与我预期的不同。我看到对于 ToggleButton
,如果您单击该按钮,文本会发生变化。对于 Switch
,我看到没有文字,但您可以向左或向右滑动开关以显示某种“开/关”功能。理想情况下,我想要一个双态切换,类似于这张照片:
但我似乎找不到某种可以为我执行此操作的切换按钮。 Switch
没有文本,ToggleButton
有文本,但只有一个正在显示的“状态”。我试着研究其他的,比如 https://github.com/jlhonora/multistatetogglebutton但这更适用于多个状态:我只想在切换按钮中使用 2 个状态。任何帮助,将不胜感激。谢谢!
Switch
es 是你想要的。
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