简体   繁体   中英

Unable to use only Light or Dark theme on Nativescript

I'm developing a Nativescript (version 6.3.3) app with Angular 8.2 and @nativescript/theme 2.2.1 with scss themes. I'm trying to use only Dark (or only Light) theme regardless of system mode (Dark/Light) but nothing seems to work. I followed this guide https://github.com/NativeScript/theme and I used custom color variables setting the dark ones equal to the light ones but it doesnt' work. Can someone support me?

If you want to force Light or Dark mode only on iOS you can add the following to your Info.plist file.

For light mode:

    <key>UIUserInterfaceStyle</key>    
    <string>Light</string>    

For dark mode:

    <key>UIUserInterfaceStyle</key>    
    <string>Dark</string>    

Hope this helps!

Also {N} Theme 2.3.x have some important fixes to force the mode. Try with 2.3.2.

For Android, First add this code in main.ts or main.js

import Theme from "@nativescript/theme";
Theme.setMode(Theme.Light);

Then change this value in styles.xml file located in folder values-v29 from true to false

<item name="android:forceDarkAllowed">false</item>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM