Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable dark theme in Ionic

I'm designing an Ionic app, and I would like it to have white backgrounds and black texts whether the user has enabled the dark theme or not.

This is what I want: dark theme disabled

However, when I enable the dark theme on an Android phone, it gets automatically converted to this:

dark theme enabled

I want to prevent this from happening. I've searched online and found many articles that describe how to apply the dark theme, but I haven't found anything about disabling it.

One solution I've thought about is explicitly enabling the dark theme, and then setting the same colors for the dark theme as for the light theme. However, I think that approach might be undesirable, as it involves writing a lot of redundant code.

Can you think of any alternative solution(s)?

like image 677
Aldán Creo Avatar asked Sep 08 '20 13:09

Aldán Creo


People also ask

How do I turn off Dark mode in ionic?

Go to Settings. Then, tap on Theme. You can either choose System Default or Light. Select Light to eliminate the Dark mode.

How do I turn off Dark mode in ionic 4 app?

One way to remove the dark theme would be by editing the variables. scss file and removing this style rule: @media (prefers-color-scheme: dark) { ... } That media query is the one that changes all the colors of the CSS custom properties when the users selects the dark theme on the device.

How do you force a light in ionic?

Press Crtl + Shift + P on PC or Cmd + Shift + P on Mac.

Why is Ionic App dark?

You're probably supporting Dark Mode. Check Settings/Display & Brightness/Dark mode and see if it reflects in your app. My app just starting do this too.


1 Answers

One way to remove the dark theme would be by editing the variables.scss file and removing this style rule:

@media (prefers-color-scheme: dark) {
  ...
}

That media query is the one that changes all the colors of the CSS custom properties when the users selects the dark theme on the device.

Please also take a look at the color-scheme meta-tag from the index.html file:

<meta name="color-scheme" content="light dark" />

You can find more information about it in the Ionic Docs

like image 140
sebaferreras Avatar answered Oct 11 '22 02:10

sebaferreras