I am trying to implement a dark theme into my android app using the android daynight theme. It currently changes the theme but i do not think it recreates the activity like i want it to. In java they have AppCompatDelegate.setDefaultNightMode()
which apparently now automatically recreates the activity but i cannot find the c# way to do this in xamarin android?
My current implementation is:
switch (selectedSpinnerItem)
{
case "Light":
((AppCompatActivity)Activity).Delegate.SetLocalNightMode(AppCompatDelegate.ModeNightNo);
break;
case "Dark":
((AppCompatActivity)Activity).Delegate.SetLocalNightMode(AppCompatDelegate.ModeNightYes);
break;
case "System Preference":
((AppCompatActivity)Activity).Delegate.SetLocalNightMode(AppCompatDelegate.ModeNightFollowSystem);
break;
}
I do not think this is the correct way to do it.