问题描述
我正在设计一个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.
这就是我想要的:
但是,当我在Android手机上启用深色主题时,它将自动转换为以下主题:
However, when I enable the dark theme on an Android phone, it gets automatically converted to this:
我想防止这种情况的发生.我在网上搜索过,发现有许多文章描述了如何应用深色主题,但是我还没有发现有关禁用它的任何信息.
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)?
推荐答案
在这种情况下,当应用无法识别代码的暗模式支持时,小米MIUI会强制采用尽力而为"的暗模式.也就是说,基本上所有白色都会变成黑色,反之亦然,但是其他一些颜色也会自动变暗.
In this case, Xiaomi MIUI forces a 'best effort' dark mode when the app doesn't recognize a dark mode support on it's code. That's is, basically every white will be black and vice versa, but also some other colors will be darkened automatically.
为避免这种情况,只需向MIUI告知"我们的应用程序是兼容暗模式的,即使没有任何其他更改,因此实际上暗模式和亮模式将相同,但MIUI不会干预带有应用程序的颜色.
To avoid this, just 'inform' to the MIUI that our app is dark mode compatible, even if there isn't any extra changes, so in fact dark and light mode will be the same, but MIUI won't interfered with the colors of the app.
只需将< head>
放入下一行:
<meta name="color-scheme" content="light dark" />
重要提示:现在您的应用将兼容暗模式,因此请谨慎设置组件的每种颜色和背景,如果不设置,并且允许使用默认值,请记住,暗的默认值并不相同和灯光模式.
Important: Now your app will be dark mode compatible, so be carefull to set every color and background of your components, if not and you let for the defaults, keep in mind that the defaults don't be the same for dark and light modes.
这篇关于在Ionic中禁用深色主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!