Skip to main content
heyo
Associate III
Nov 21, 2022 8:22 AM UTC
Solved

Toggle button

Is it possible to change toggle button state?

This topic has been closed for replies.
Osman SOYKURT
Osman SOYKURTBest answer
ST Technical Moderator
Nov 21, 2022 9:41 AM UTC

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

1 reply

Osman SOYKURT
Osman SOYKURTBest answer
ST Technical Moderator
Nov 21, 2022 9:41 AM UTC

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