Android Application Resource Basics: Style Configuration

Style resources define interface formatting and visual properties. They can be applied to individual View components (directly from layout files) or to entire Activity or application instances (via manifest file).

Note: Styles are simple resources referenced using the value provided in their name attribute, not the XML filename. This allows combining style resources with other simple resources under a single <resources> root element in one XML file.

File Location

res/values/<filename>.xml The filename can be arbitrary. The <style> element's name attribute serves as the resource ID.

Resource Reference

In XML: @[package:]style/<style_name>

Syntax

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style
        name="style_identifier"
        parent="@[package:]style/inherited_style">
        <item
            name="[package:]style_property_name">style_value</item>
    </style>
</resources>

Key Elements

  • <resources>: Required root node. No attributes.
  • <style>: Defines a single style. Contains <item> elements.
    • name: Required string. Style's unique identifier, used to aply it to UI components or app contexts.
    • parent: Optional reference to another style resource from which properties are inherited.
  • <item>: Specifies a single style property. Must be a child of <style>.
    • name: Required attribute resource. Name of the style property, with optional package prefix (e.g., android:textColor).

Examples

Style Definition File (res/values/styles_custom.xml)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomizedText" parent="@style/TextBase">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">#008</item>
    </style>
</resources>

Applying the Style to a TextView (res/layout/activity_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<EditText
    style="@style/CustomizedText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Greetings, Android!" />

Tags: Android Application Resources UI Styling XML Layouts Android Development

Posted on Thu, 07 May 2026 08:50:15 +0000 by validkeys