Je viens de changer le fond d’un ToggleButton
, et maintenant je cherche à changer le texte ON / OFF qui vient avec. Quelle est la manière la plus simple de faire ça?
Vous pouvez utiliser les éléments suivants pour définir le texte à partir du code:
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.
Pour définir le texte à l’aide de XML, utilisez ce qui suit:
android:textOff="The text for the button when it is not checked." android:textOn="The text for the button when it is checked."
Cette information vient d’ ici
Dans l’exemple android:textOff
vous accédez, ils le modifient en Jour / Nuit en utilisant android:textOn
et android:textOff
Définissez le XML comme suit:
Il semble que vous n’ayez plus besoin de toggleButton.setTextOff (textOff); et toggleButton.setTextOn (textOn) ;. Le texte de chaque état modifié changera simplement en incluant les caractéristiques xml pertinentes. Cela remplacera le texte par défaut ON / OFF.
Oui, vous pouvez changer le bouton marche / arrêt
android:textOn="Light ON" android:textOff="Light OFF"
Référer pour plus
http://androidcoding.in/2016/09/11/android-tutorial-toggle-button