title: How do you change android app theme colors with default phone settings?
body: <p>I'm new to android styles and themes, and I've looked at a a lot of different posts that don't seem to fix the problem I'm facing.</p>
  <p>The solutions I've tried all seem to look almost identical to <a href="https://www.geeksforgeeks.org/how-to-create-a-dark-mode-for-a-custom-android-app-in-kotlin/" rel="nofollow noreferrer">this one</a> (usually not including the physical in-app switch), so it's possible I'm just missing something here!</p>
  <p>Basically, I want the background of the app I'm developing to switch between light and dark colors depending on the setting of the phones default dark mode setting. So if the phone is in dark mode, the darker colors apply when you open the app, and if it's in light mode the lighter colors get applied.</p>
  <p>To be clear, I'm talking about the light/dark mode that you set in your phone settings or slide down screen, not a switch within the app.</p>
  <p>I have switched both the style's and theme's parents to use dayNight.</p>
  <p><strong>Quick note</strong></p>
  <p><em>the style's name is currently LightTheme, that's just from me experimenting with different things to try and get it working!</em></p>
  <p><strong>styles.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;resources&gt;
      &lt;style name=&quot;LightTheme&quot; parent=&quot;Theme.MaterialComponents.DayNight&quot;&gt;
          &lt;item name=&quot;colorPrimary&quot;&gt;@color/light_blue&lt;/item&gt;
          &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/dark_blue&lt;/item&gt;
          &lt;item name=&quot;colorSecondary&quot;&gt;@color/dark_purple&lt;/item&gt;
          &lt;item name=&quot;colorSecondaryVariant&quot;&gt;@color/light_purple&lt;/item&gt;
          &lt;item name=&quot;colorAccent&quot;&gt;@color/yellow&lt;/item&gt;
          &lt;item name=&quot;colorButtonNormal&quot;&gt;@color/orange&lt;/item&gt;
      &lt;/style&gt;
  &lt;/resources&gt;
  </code></pre>
  <p><strong>Themes.xml</strong></p>
  <pre><code>&lt;resources xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;
      &lt;!-- Base application theme. --&gt;
      &lt;style name=&quot;Theme.Whereshouldieat&quot; parent=&quot;Theme.MaterialComponents.DayNight&quot;&gt;
          &lt;!-- Primary brand color. --&gt;
          &lt;item name=&quot;colorPrimary&quot;&gt;@color/purple_500&lt;/item&gt;
          &lt;item name=&quot;colorPrimaryVariant&quot;&gt;@color/purple_700&lt;/item&gt;
          &lt;item name=&quot;colorOnPrimary&quot;&gt;@color/white&lt;/item&gt;
          &lt;!-- Secondary brand color. --&gt;
          &lt;item name=&quot;colorSecondary&quot;&gt;@color/teal_200&lt;/item&gt;
          &lt;item name=&quot;colorSecondaryVariant&quot;&gt;@color/teal_700&lt;/item&gt;
          &lt;item name=&quot;colorOnSecondary&quot;&gt;@color/black&lt;/item&gt;
          &lt;!-- Status bar color. --&gt;
          &lt;item name=&quot;android:statusBarColor&quot; tools:targetApi=&quot;l&quot;&gt;?attr/colorPrimaryVariant&lt;/item&gt;
          &lt;!-- Customize your theme here. --&gt;
      &lt;/style&gt;
  &lt;/resources&gt;
  </code></pre>
  <p>I can set themes or styles for the whole app or activity, but I don't want the background of smaller children elements to have the same color background as the very &quot;back&quot; of the app (for example, I don't want recyclerview items to share a background color with the background of the app, because then they don't stand out like I need them too). I can set the style of the views, but then they don't change with the light/dark mode of the phone.</p>
  <p>currently I have the colors changing with what seems like an incorrect workaround to the problem, which is this piece of code in
  <strong>MainActvitiy.kt</strong></p>
  <pre><code> when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
  
              Configuration.UI_MODE_NIGHT_NO -&gt; {
                  val backgroundColor = ContextCompat.getColor(this, R.color.light_blue)
  
                  findViewById&lt;ConstraintLayout&gt;(R.id.main_activity_layout).setBackgroundColor(backgroundColor)
              }
  
              Configuration.UI_MODE_NIGHT_YES -&gt; {
                  val backgroundColor = ContextCompat.getColor(this, R.color.black)
  
                  findViewById&lt;ConstraintLayout&gt;(R.id.main_activity_layout).setBackgroundColor(backgroundColor)
              }
          }
  </code></pre>
  <p>What I <strong>CAN</strong> do, is have the app switch between a white and black background using the day or night mode as I'm describing. Is it as easy as just changing the default colors for these &quot;modes&quot;? If so, I just need to know how to do that!</p>
  <p>I appreciate any help, thank you!!</p>