What is difference among styles.xml and themes.xml

前端 未结 6 1351
时光说笑
时光说笑 2020-12-13 03:37

May I know what is the difference between styles.xml and themes.xml? To me, they just look same as both XML are in the same format.



        
相关标签:
6条回答
  • 2020-12-13 03:56

    Quoted from Android API guide:

    To create a set of styles, save an XML file in the res/values/ directory of your project. The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder. The root node of the XML file must be <resources>.

    Full documentation

    So I guess it really doesn't matter if you put any styles in any files as long as it's an xml file which locates in res/values/ folder.

    0 讨论(0)
  • 2020-12-13 03:57

    There is no functional difference between styles.xml and themes.xml as many answers have indicated.

    It is worth noting that Google's iosched2014 app has ONLY a styles.xml (no themes.xml).

    https://github.com/google/iosched

    0 讨论(0)
  • 2020-12-13 03:57

    Hi here is an article regarding to the difference between styles and themes XML in android please go through

    And also here the android documentation regarding to styles and themes in Android.

    0 讨论(0)
  • 2020-12-13 03:59

    I am just realizing that for example Toolbar text colors go into a theme declaration, and for other aspects go into a style declaration

    <style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
    </style>
    
    <style name="ToolbarStyle" parent="Base.Widget.AppCompat.Toolbar">
        <item name="android:minHeight">?attr/actionBarSize</item>
        <item name="android:background">@color/colorPrimary</item>
    </style>
    

    And in the toolbar declaration

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/ToolbarStyle"
        android:theme="@style/ToolbarTheme">
    </android.support.v7.widget.Toolbar>
    

    I tried to omit the theme by moving its items into the style, but that didn't work. So in this case it seems as these are just styles which are as theme since they affect the inherited children in the toolbar such as the textfields.

    0 讨论(0)
  • 2020-12-13 04:13

    Taken from the Styles and Themes document, in the Defining Styles section:

    To create a set of styles, save an XML file in the res/values/ directory of your project. The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder.

    The root node of the XML file must be <resources>.
    
    0 讨论(0)
  • 2020-12-13 04:15

    Out of the whole page of the Styles and Themes. You may be looking for this line.

    When you apply a style to a single View in the layout, the properties defined by the style are applied only to that View. If a style is applied to a ViewGroup, the child View elements will not inherit the style properties—only the element to which you directly apply the style will apply its properties. However, you can apply a style so that it applies to all View elements—by applying the style as a theme.

    When you apply as theme, it changes everything in scope, depending if you applied it on Activity or Application. Style is more 'local'.

    0 讨论(0)
提交回复
热议问题