Using 'Any Component' Blocks to Swap Color Palettes?

Howdy! I'm teaching App Inventor for the first time and wanted to expand my horizons. For context, I want to create an app essentially for an RPG character sheet. I just started working on the essential code, but one element I do want to include is an option to change the aesthetics of the app on the fly, like a 'theme' list for the user to choose what background/font colors will appear on the app during run-time.

I feel, and I've read in other posts that the 'Any component' blocks will save me time in swapping the color palette of each button/label, but something is not lining up. I'm following all the advice from those who have asked about it in the past, but I keep butting up against the 'Property setter was expecting a com.google.appinventor.components.runtime.Button component but got a...' error when I attempt to use the procedure that includes this block.

So in my screenshots you'll see a list of buttons/labels whose colors I want to change; a procedure for initializing the lists and setting the new color palette up; and the 'themePicker' Listpicker that is SUPPOSED to activate the change. Some blocks are disabled because I wasn't sure if they were necessary. I'm still an amateur, but I hope I'm at least explaining my goals for this code clearly!

What can I do better? Any and all guidance will be sincerely appreciated. Thank you friends!

This block? do you mean a block that is a Button? What happens if you do not attempt to change Button properties but change everything else?

This error might happen if you use the routine when you have a Button.Visible = false . I expect you can only use the routine if the Button is visible I think. You could get the error because you have some many Properties being reset and you are experiencing a timing error.

Someone might have different ideas. It is impossible to debug code like yours without an example aia or the full Project aia because one has to experiment.

You have the right idea. See this example:

setTheme.aia (2.8 KB)

You are getting the Property setter was expecting a com.google.appinventor.components.runtime.Button component but got a... error because somewhere in your blocks you are not providing a component block.

1 Like

Totally fair. Like I said, this feature is just icing on the cake of this app; I haven't actually built much of the code in outside of this.
When I get the error, I was referring to using the 'Any Component' blocks in particular to change the properties of a whole list of components at once. I don't have any invisible or disabled components on initialization, but I'm definitely going to test your theory about it just being too much all at once. I also know from reading other forum posts about the 'Any Component' blocks that buttons can't be added to a list as easily as other data. So your feedback is very helpful in just illustrating how many ways a plan can go awry!

Hey, sorry for the late response- I haven't had time to sit down and think this through in a few days.
Your solution was correct, but I'd made another silly error that stopped me from realizing it at first. I just discovered that I'd accidentally included some listPicker components in my 'Any Component' blocks referring to 'Buttons.' This must have been an issue from the get-go, so I may actually not have gotten any errors if I'd seen it sooner.
Anyway, I'm glad I posted - this is a topic I haven't seen explored too deeply, so I hope others can benefit from your advice!
Thank you sincerely.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.