Dark mode issue

hello everyone, I added a night mode to my app,it works good without a background image but when i’m adding a background to the screen it comeback to light mode by itself, this is the blocks i used

s

Use TinyDB to store user preferences and run a procedure every time the screen is initialized. Use the same procedure on Switch.Clicked event to change between themes.

I’m still a beginner, will you please clarify what does TinyDB mean, thank you for your reply

Check it out here

help,I’m stuck here :slightly_smiling_face:


Check this screenshot.

I’m so sorry for bothering you, but it did not work, I tried these blocks i don’t know what’s wrong?

The blocks are incorrect. Delete the light_mode and dark_mode procedures, you don’t need them. The procedure2 is all you need:

I have added an extra bit in screen_intialise that will put the switch in the correct position too.
Explanation of the blocks: When the user clicks the switch, it saves the theme as dark if it is checked and as light if it is not. It then calls (triggers) the procedure2 which changes the background color depending on the value saved in theme. When the screen initialises, procedure2 checks what’s saved in theme and sets the colors.

TinyDB saves data on the users phone, think of the tag as the variable name and value to store is the value it holds. I recommend practicing some more and getting familiar with Kodular.

I appreciate your answer it worked well, but it’s still not able to work when i’m adding a background image
21

1 Like

Background image and backgorund color doesn’t work on same time.

So, there is no way to fix that?

Use dark image for dark theme and light image for light theme as screen background

are those blocks correct for that

Test it on companion… remember to get two different images for background…

I tested them but, I didn’t get any result

You need to create an image with a dark background too. Can you show your other image here.

sure,
mosque-g888d1d441_640
mosque-gae086fdef_640

Works fine for me. Did you use the companion?

yes,i did use it

What happened?