Nativescript Angular Android App forced light mode not working

333 Views Asked by At

My nativescript android app build using angular in API 29 doesn't get the styles.xml settings from values-v29 folder.

<style name="AppThemeBase29" parent="AppThemeBase21">
    <item name="android:forceDarkAllowed">false</item>
</style>

The values-v29 folder only contains the styles.xml file. I have set the forceDarkAllowed to false as shown above. Besides that, I have also set the theme dynamically in main.tns.ts file by:

Theme.setMode(Theme.Light);

What am I missing? It works on IOS by changing the Info.plist file.

native script version: 6.5.0 angular version: 8

1

There are 1 best solutions below

1
William Juan On

For Android you might have to implement an application delegate, in your main.ts like below

import { android, on, launchEvent, ApplicationEventData } from '@nativescript/core/application';

// Typescript will require you to define those types
declare namespace androidx {
 export namespace appcompat {
  export namespace app {
   export const AppCompatDelegate: any;
  }
 }
}

if (android) {
 on(launchEvent, (args: ApplicationEventData) => {
  androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode(androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO)
 });
}