Skip to content

Controlling what users view when users switch modes

Devrath edited this page May 28, 2021 · 1 revision

Controlling the resources displayed on the screen using the styles using the modes

  • We can achieve this using the styles having two values folder for normal mode and dark mode
    • res/values/styles.xml
    • res/values-night/styles.xml
  • To create values-night folder
    • Right-click on the values folder
    • Select new from the options.
    • In the available qualifiers select Night-Mode and push to right using the middle selection arrows.
    • Then Select Not Night mode
    • Give the file name as styles
    • Press ok
  • In the res/values/styles.xml add the below entries
  <style name="TextStyle" parent="AppTheme">
    <item name="android:text">@string/let_me_out</item>
  </style>

  <style name="ImageStyle" parent="AppTheme">
    <item name="android:src">@drawable/airlock</item>
  </style>
  • In the res/values-night/styles.xml add the below entries
  <style name="TextStyle" parent="AppTheme">
    <item name="android:text">@string/let_me_out</item>
  </style>

  <style name="ImageStyle" parent="AppTheme">
    <item name="android:src">@drawable/astronaut</item>
  </style>