Mario Esposito
Mario Esposito

Reputation: 1

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?

Upvotes: 0

Views: 1048

Answers (3)

Justin Nadar
Justin Nadar

Reputation: 21

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>

Upvotes: 1

Bundyo
Bundyo

Reputation: 2193

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

Upvotes: 0

Tyler Blake
Tyler Blake

Reputation: 136

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!

Upvotes: 2

Related Questions