Change background Color of any Button

Hello together,

my name is Nils from Germany.
This is my first app that I create with the MIT App Inventor. In my app I have a lot of buttons and each button has a background color that can change when I click the button. The last button on the page is a "Clear All" button. When I press this button, every background color has to turn gray again. Now my question is if there is an easier way to program this like I did in the picture below. I probably need this function more often and then I have to make it so cumbersome every time.

This is only part of the buttons. (My buttons are all called LED ... with an ascending number)

Thanks for helping me.


You can male a list of your button components, then iterate over this list using the anyComponent blocks to change properties



As @TIMAI2 said, you can create a list of buttons, then use the 'for each item in list' block. The 'for each item in list' block does the 'do' part of the block for every item/component in the list.

@TIMAI2 thanks for this tip. But do I understand correctly that I have to name all the buttons in the list? Isn't it also possible that I can say (for example) "all buttons in this table(or horzontalscrollArrangement) -> background color changed to gray?" or "all LED buttons (and then count up a variable) -> background color changed to gray?"

Perhaps it would also be possible to color all buttons in the whole app in gray and then to color the two or three buttons that should not be gray again. Is that feasible?

Thanks and regards


Currently, only making a list of the components is the way. The components like buttons and labels are all created at runtime, so they do not "exist" until created and each have a unique name, each time to start/reload the app.

You can use logic to select the buttons you do not want to change, and omit them from your iteration, or change all to gray, then change the ones you want to a different colour, using your button list to get indexes.

OK. So the only thing left for me to do is to create a list with every single button.

Thank you