Skip to main content
heyo
Associate III
November 21, 2022
Solved

Toggle button

  • November 21, 2022
  • 1 reply
  • 1286 views

Is it possible to change toggle button state?

This topic has been closed for replies.
Best answer by Osman SOYKURT

Hello heyo,

Yes, by default the toggle button will react when you click on it and you can get the status of your toggle button with this function :

toggleButton1.getState()

If you want to set a state yourself, you can use this function :

toggleButton1.forceState(!toggleButton1.getState());
// here it will invert your toggle button state, so if true then false, and if false then true

I created a small example that you can get inspiration from if you want.

/Osman

1 reply

Osman SOYKURT
Osman SOYKURTBest answer
ST Technical Moderator
November 21, 2022

Hello heyo,

Yes, by default the toggle button will react when you click on it and you can get the status of your toggle button with this function :

toggleButton1.getState()

If you want to set a state yourself, you can use this function :

toggleButton1.forceState(!toggleButton1.getState());
// here it will invert your toggle button state, so if true then false, and if false then true

I created a small example that you can get inspiration from if you want.

/Osman

ST Software Developer | TouchGFX