更改切换按钮的Andr​​oid的开/关文按钮、Andr、oid

2023-09-05 01:39:27 作者:巴黎左岸的咖啡馆

我只是changed一个切换按钮 的背景下,现在我期待改变,来了与它的ON / OFF文本。什么是做到这一点的最简单的方法是什么?

I just changed the background of a ToggleButton, and now I'm looking to change the ON/OFF text that comes up with it. What is the easiest way to do this?

推荐答案

您可以使用下面的设置从code中的文本:

You can use the following to set the text from the code:

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设置文本,使用以下命令:

To set the text using xml, use the following:

android:textOff="The text for the button when it is not checked."
android:textOn="The text for the button when it is checked." 

此信息是从这里

This information is from here