I want to enforce the lightmode theme to my android application.
I've added this line of code to the app.cs
public partial class App : Application
{
public App()
{
InitializeComponent();
App.Current.UserAppTheme = OSAppTheme.Light;
MainPage = new MainPage();
}
I read this https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/theming/system-theme-changes but don't understand what I'm missing.
CodePudding user response:
Assigning App.Current.UserAppTheme
is not enough, you have to define your light or/and dark theme through styles for different controls using the xaml extension AppThemeBinding
like shown in examples in documentation link.
CodePudding user response:
I've solved this by placing this line of code in the MainActivity.cs from the Android project
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
Placing this line of code directly at the start of the OnCreate method solves the problem.