Custom styles and themes

To customise the appearance of multiple objects at once with consistent visuals you can use:

  • Themes – generate an app-wide definition of visual attributes
  • Styles – create a set of attributes which can be applied individually to multiple objects

In styles.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> // Uses the light Android theme. Exclude '.Light.DarkActionBar' for dark theme
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item> // Colors defined in the colors.xml file
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>


    <!-- Style for textViews that are displayed in a list on the main screen-->
    <style name="MainActivityLabelStyle"> // Custom name which is referenced in the layout .xml file for each object the styles are being applied to: style="@style/ActivityLabelStyle"
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">80dp</item>
        <item name="android:textColor">@android:color/black</item>
    </style>

    <style name="BoldMainActivityLabelStyle" parent="MainActivityLabelStyle"> // Style which inherits all of the MainActivityLabelStyle attributes and adds bold text
        <item name="android:textStyle">bold</item>
    </style>

</resources>