skip to Main Content

In the newer version of Android Studio, I cant see styles.xml, but in the values directory, there are two new XML, theme.xml and theme.xml(night).

Does it actually replace the work of styles.xml OR If different what is the difference between them??

2

Answers


  1. Using XML attributes in resvalues doesn’t actually depend on the file name, you can define any of which like a <string> in another file like style.xml.

    Even you can change the name of the style.xml to something that you’d like to.

    In recent Android studio versions styles.xml is replaced by themes.xml, but the latter provides a night version for dark mode.

    Login or Signup to reply.
  2. styles is a collection of attributes which define how a certain ui looks like ex: editText or textView a theme meanwhile decides how your whole app looks(a single theme can have multiple styles depends on your design), the difference between both themes day and night is to make your app adapt to day mode and night mode. Because now in android OS you can force dark mode.

    As a developer you need to have your app prepared for this.

    How to use this

    give different colors to both your themes labelled in items(below is from a theme file)

      <resources xmlns:tools="http://schemas.android.com/tools">
       <!-- Base application theme. -->
       <style name="Theme.<Your app name>" <---- this is autogenrated this wil be the id to be used
       parent="Theme.MaterialComponents.DayNight">
         </style>
         </resources>
    

    To use in textview or button or layout file simpley just:

        <TextView
        android:id="@+id/tv_StackOverflow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Theme.<Your app name>" /> <---insert your style name inside the theme.
    

    Now when user force switch on dark mode in developer mode in their phone , your app will immediately adapt to it and change colors of its UI.

    More info can be found here – https://developer.android.com/guide/topics/ui/look-and-feel/themes

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search