首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >更改切换按钮Android的开/关文本

更改切换按钮Android的开/关文本
EN

Stack Overflow用户
提问于 2011-12-30 04:56:20
回答 5查看 110K关注 0票数 85

我只是changed the background of a ToggleButton,现在我正在寻找更改与它一起出现的开/关文本。做这件事最简单的方法是什么?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-12-30 05:01:04

您可以使用以下内容设置代码中的文本:

代码语言:javascript
复制
toggleButton.setText(textOff);
// Sets the text for when the button is first created.

toggleButton.setTextOff(textOff);
// Sets the text for when the button is not in the checked state.

toggleButton.setTextOn(textOn);
// Sets the text for when the button is in the checked state.

要使用xml设置文本,请使用以下命令:

代码语言:javascript
复制
android:textOff="The text for the button when it is not checked."
android:textOn="The text for the button when it is checked." 

此信息来自here

票数 210
EN

Stack Overflow用户

发布于 2011-12-30 05:02:07

在您链接到的示例中,他们使用android:textOnandroid:textOff将其更改为白天/夜晚

票数 16
EN

Stack Overflow用户

发布于 2014-12-20 17:18:26

将XML设置为:

代码语言:javascript
复制
<ToggleButton
    android:id="@+id/flashlightButton"
    style="@style/Button"
    android:layout_above="@+id/buttonStrobeLight"
    android:layout_marginBottom="20dp"
    android:onClick="onToggleClicked"
    android:text="ToggleButton"
    android:textOn="Light ON"
    android:textOff="Light OFF" />
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8673347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档