0

This is my style in attr_styles.xml

<style name="AttrStyles" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="calendarAppointmentView">@style/calendar_appointment_view</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="alertDialogTheme">@style/white_style</item>
</style>

And I have 2 colors.xml files. 1 is in values, the other in values-night.

If I select from phone settings DarkMode on or off, it works. BUT I want to have a Spinner in my app, to have: AUTO, ON, OFF. How can I force it to show the light colors (values) or to show the dark colors (values-night) based on that spinner?

I tried in my App.kt class (Application class) to call onCreate() this:

    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

or

    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

But nothing happens. What am I doing wrong?

rosu alin
  • 5,674
  • 11
  • 69
  • 150

1 Answers1

0

After searching for your qestion for about 2 minutes, I came across a similar question that pretty much has the answer you're looking for. It seems like you have to use the method setTheme.

  • You are missing the point. I want a Spinner to select and force which mode I want. setTheme I can set to DayNight and it will take the mode based on DarkTheme ON or OFF. OK, if it's off, I setTheme to android.R.style.theme . and it's light mode on. But how can I set the theme to forcefully use the values-night. AKA force dark mode on , even if settings are on light – rosu alin Jan 23 '20 at 15:09