More resource types  |  Views  |  Android Developers Skip to main content / English Deutsch Español – América Latina Français Indonesia Italiano Polski Português – Brasil Tiếng Việt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文 – 简体 中文 – 繁體 日本語 한국어 Android Studio Sign in Home Guides Home Guides Android Studio Architecture for Views Recommendations for Android architecture About view binding Migrate from Kotlin synthetics to view binding Data binding library About data binding Get started Layouts and binding expressions Work with observable data objects Generated binding classes Binding adapters Bind layout views to Architecture Components Two-way data binding Lifecycle for Views Handling lifecycles with lifecycle-aware components Save UI states ViewModel overview Create ViewModels with dependencies ViewModel Scoping APIs Saved State module for ViewModel ViewModel APIs cheat sheet LiveData Use Kotlin coroutines with lifecycle-aware components Paging for Views Page from network and database Transform data streams Manage and present loading states Test your Paging implementation Load and display paged data Migrate to Paging 3 About Paging 2 Display paged lists Load paged data Dependency injection for Views Dependency injection with Hilt Manual dependency injection Hilt testing guide App entry points for Views The activity lifecycle App resources for Views App resources overview Handle configuration changes Localize your app Complex XML resources Drawable Layout Animation String resources Color state list Menu Font Style More types UI layer for Views UI layer UI events UI State production Android Developers Develop Core areas UI Views Guides More resource types Stay organized with collections Save and categorize content based on your preferences. This page defines the following types of resources that you can externalize: Bool XML resource that carries a boolean value. Color XML resource that carries a color value (a hexadecimal color). Dimension XML resource that carries a dimension value (with a unit of measure). ID XML resource that provides a unique identifier for application resources and components. Integer XML resource that carries an integer value. Integer array XML resource that provides an array of integers. Typed array XML resource that provides a TypedArray (which you can use for an array of drawables). Bool A boolean value defined in XML. Note: A bool is a simple resource that is referenced using the value provided in the name attribute, not the name of the XML file. As such, you can combine bool resources with other simple resources in one XML file, under one <resources> element. file location: res/values/filename.xml The filename is arbitrary. The <bool> element's name is used as the resource ID. resource reference: In Java: R.bool.bool_name In XML: @[package:]bool/bool_name syntax: <?xml version="1.0" encoding="utf-8"? <resources> <bool name="bool_name" >[true | false]</bool </resources elements: <resources> Required. This is the root node. No attributes. <bool> A boolean value: true or false. Attributes: name String. A name for the bool value. This is used as the resource ID. example: XML file saved at res/values-small/bools.xml: <?xml version="1.0" encoding="utf-8"? <resources> <bool name="screen_small"true</bool <bool name="adjust_view_bounds"true</bool </resources The following application code retrieves the boolean: Kotlin val screenIsSmall: Boolean = resources.getBoolean(R.bool.screen_small) Java Resources res = getResources(); boolean screenIsSmall = res.getBoolean(R.bool.screen_small); The following layout XML uses the boolean for an attribute: <ImageView android:layout_height="fill_parent" android:layout_width="fill_parent" android:src="@drawable/logo" android:adjustViewBounds="@bool/adjust_view_bounds" / Color A color value defined in XML. The color is specified using an RGB value and alpha channel. You can use a color resource any place that accepts a hexadecimal color value. You can also use a color resource when a drawable resource is expected in XML, such as android:drawable="@color/green". The value always begins with a pound (#) character, which is followed by the Alpha-Red-Green-Blue information in one of the following formats: #RGB #ARGB #RRGGBB #AARRGGBB Note: A color is a simple resource that is referenced using the value provided in the name attribute, not the name of the XML file. As such, you can combine color resources with other simple resources in one XML file, under one <resources> element. file location: res/values/colors.xml The filename is arbitrary. The <color> element's name is used as the resource ID. resource reference: In Java: R.color.color_name In XML: @[package:]color/color_name syntax: <?xml version="1.0" encoding="utf-8"? <resources <color name="color_name" >hex_color</color </resources elements: <resources> Required. This is the root node. No attributes. <color> A color expressed in hexadecimal. Attributes: name String. A name for the color. This is used as the resource ID. example: XML file saved at res/values/colors.xml: <?xml version="1.0" encoding="utf-8"? <resources <color name="opaque_red"#f00</color <color name="translucent_red"#80ff0000</color </resources The following application code retrieves the color resource: Kotlin val color: Int = resources.getColor(R.color.opaque_red) Java Resources res = getResources(); int color = res.getColor(R.color.opaque_red); The following layout XML applies the color to an attribute: <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/translucent_red" android:text="Hello"/ Dimension A dimension value defined in XML. A dimension is specified with a number followed by a unit of measure, such as 10px, 2in, or 5sp. The following units of measure are supported by Android: dp Density-independent pixels: an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1 dp is roughly equal to 1 px. When running on a higher density screen, the number of pixels used to draw 1 dp is scaled up by a factor appropriate for the screen's dpi. Likewise, when on a lower-density screen, the number of pixels used for 1 dp is scaled down. The ratio of dps to pixels changes with the screen density, but not necessarily in direct proportion. Using dp units instead of px units is a solution to making the view dimensions in your layout resize properly for different screen densities. It provides consistency for the real-world sizes of your UI elements across different devices. sp Scale-independent Pixels - This is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference. pt Points: 1/72 of an inch based on the physical size of the screen, assuming a 72 dpi density screen. px Pixels: corresponds to actual pixels on the screen. We don't recommend using this unit, because the actual representation can vary across devices. Different devices can have a different number of pixels per inch and might have more or fewer total pixels available on the screen. mm Millimeters: based on the physical size of the screen. in Inches: based on the physical size of the screen. Note: A dimension is a simple resource that is referenced using the value provided in the name attribute, not the name of the XML file. As such, you can combine dimension resources with other simple resources in one XML file, under one <resources> element. file location: res/values/filename.xml The filename is arbitrary. The <dimen> element's name is used as the resource ID. resource reference: In Java: R.dimen.dimension_name In XML: @[package:]dimen/dimension_name syntax: <?xml version="1.0" encoding="utf-8"? <resources <dimen name="dimension_name" >dimension</dimen> </resources> elements: <resources> Required. This is the root node. No attributes. <dimen> A dimension, represented by a float followed by a unit of measurement (dp, sp, pt, px, mm, in). Attributes: name String. A name for the dimension. This is used as the resource ID. example: XML file saved at res/values/dimens.xml: <?xml version="1.0" encoding="utf-8"? <resources <dimen name="textview_height"25dp</dimen <dimen name="textview_width"150dp</dimen <dimen name="ball_radius"30dp</dimen <dimen name="font_size"16sp</dimen </resources The following application code retrieves a dimension: Kotlin val fontSize: Float = resources.getDimension(R.dimen.font_size) Java Resources res = getResources(); float fontSize = res.getDimension(R.dimen.font_size); The following layout XML applies dimensions to attributes: <TextView android:layout_height="@dimen/textview_height" android:layout_width="@dimen/textview_width" android:textSize="@dimen/font_size"/ ID A unique resource ID defined in XML. Using the name you provide in the <item> element, the Android developer tools create a unique integer in your project's R.java class, which you can use as an identifier for an application resources, such as a View in your UI layout, or a unique integer for use in your application code, such as an ID for a dialog or a result code. Note: An ID is a simple resource that is referenced using the value provided in the name attribute, not the name of the XML file. As such, you can combine ID resources with other simple resources in one XML file, under one <resources> element. Also, an ID resource doesn't reference an actual resource item: it is a unique ID that you can attach to other resources or use as a unique integer in your application. file location: res/values/filename.xml The filename is arbitrary. resource reference: In Java: R.id.name In XML: @[package:]id/name syntax: <?xml version="1.0" encoding="utf-8"? <resources> <item type="id" name="id_name" /> </resources> elements: <resources> Required. This is the root node. No attributes. <item> Defines a unique ID. Takes no value, only attributes. Attributes: type Must be "id". name String. A unique name for the ID. example: XML file saved at res/values/ids.xml: <?xml version="1.0" encoding="utf-8"? <resources <item type="id" name="button_ok" /> <item type="id" name="dialog_exit" /> </resources The following layout snippet uses the "button_ok" ID for a Button widget: <Button android:id="@id/button_ok" style="@style/button_style" /> The android:id value here doesn't include the plus sign in the ID reference, because the ID already exists, as defined in the preceding ids.xml example. When you specify an ID to an XML resource using the plus sign, in the format android:id="@+id/name", that means that the "name" ID doesn't yet exist, and it is created. As another example, the following code snippet uses the "dialog_exit" ID as a unique identifier for a dialog: Kotlin showDialog(R.id.dialog_exit) Java showDialog(R.id.dialog_exit); In the same application, the "dialog_exit" ID is compared when creating a dialog: Kotlin override fun onCreateDialog(id: Int): Dialog? { return when(id) { R.id.dialog_exit - { ... } else - { null } } } Java protected Dialog onCreateDialog(int id) { Dialog dialog; switch(id) { case R.id.dialog_exit: ... break; default: dialog = null; } return dialog; } Integer An integer defined in XML. Note: An integer is a simple resource that is referenced using the value provided in the name attribute, not the name of the XML file. As such, you can combine integer resources with other simple resources in one XML file, under one <resources> element. file location: res/values/filename.xml The filename is arbitrary. The <integer> element's name is used as the resource ID. resource reference: In Java: R.integer.integer_name In XML: @[package:]integer/integer_name syntax: <?xml version="1.0" encoding="utf-8"? <resources <integer name="integer_name" >integer</integer> </resources> elements: <resources> Required. This is the root node. No attributes. <integer> An integer. Attributes: name String. A name for the integer. This is used as the resource ID. example: XML file saved at res/values/integers.xml: <?xml version="1.0" encoding="utf-8"? <resources <integer name="max_speed"75</integer <integer name="min_speed"5</integer </resources The following application code retrieves an integer: Kotlin val maxSpeed: Int = resources.getInteger(R.integer.max_speed) Java Resources res = getResources(); int maxSpeed = res.getInteger(R.integer.max_speed); Integer array An array of integers defined in XML. Note: An integer array is a simple resource that is referenced using the value provided in the name attribute, not the name of the XML file. As such, you can combine integer array resources with other simple resources in one XML file, under one <resources> element. file location: res/values/filename.xml The filename is arbitrary. The <integer-array> element's name is used as the resource ID. compiled resource datatype: Resource pointer to an array of integers. resource reference: In Java: R.array.integer_array_name In XML: @[package:]array/integer_array_name syntax: <?xml version="1.0" encoding="utf-8"? <resources <integer-array name="integer_array_name" <item >integer</item> </integer-array </resources elements: <resources> Required. This is the root node. No attributes. <integer-array> Defines an array of integers. Contains one or more child <item> elements. Attributes: android:name String. A name for the array. This name is used as the resource ID to reference the array. <item> An integer. The value can be a reference to another integer resource. Must be a child of an <integer-array> element. No attributes. example: XML file saved at res/values/integers.xml: <?xml version="1.0" encoding="utf-8"? <resources <integer-array name="bits" <item4</item <item8</item <item16</item <item32</item </integer-array </resources The following application code retrieves the integer array: Kotlin val bits: IntArray = resources.getIntArray(R.array.bits) Java Resources res = getResources(); int[] bits = res.getIntArray(R.array.bits); Typed array A TypedArray defined in XML. You can use this to create an array of other resources, such as drawables. The array isn't required to be homogeneous, so you can create an array of mixed resource types, but be aware of what and where the data types are in the array so that you can properly obtain each item with the TypedArray class's get...() methods. Note: A typed array is a simple resource that is referenced using the value provided in the name attribute, not the name of the XML file. As such, you can combine typed array resources with other simple resources in one XML file, under one <resources> element. file location: res/values/filename.xml The filename is arbitrary. The <array> element's name is used as the resource ID. compiled resource datatype: Resource pointer to a TypedArray. resource reference: In Java: R.array.array_name In XML: @[package:]array/array_name syntax: <?xml version="1.0" encoding="utf-8"? <resources <array name="integer_array_name" <item>resource</item> </array </resources elements: <resources> Required. This is the root node. No attributes. <array> Defines an array. Contains one or more child <item> elements. Attributes: android:name String. A name for the array. This name is used as the resource ID to reference the array. <item> A generic resource. The value can be a reference to a resource or a simple data type. Must be a child of an <array> element. No attributes. example: XML file saved at res/values/arrays.xml: <?xml version="1.0" encoding="utf-8"? <resources <array name="icons" <item@drawable/home</item <item@drawable/settings</item <item@drawable/logout</item </array <array name="colors" <item#FFFF0000</item <item#FF00FF00</item <item#FF0000FF</item </array </resources The following application code retrieves each array and then obtains the first entry in each array: Kotlin val icons: TypedArray = resources.obtainTypedArray(R.array.icons) val drawable: Drawable = icons.getDrawable(0) val colors: TypedArray = resources.obtainTypedArray(R.array.colors) val color: Int = colors.getColor(0,0) Java Resources res = getResources(); TypedArray icons = res.obtainTypedArray(R.array.icons); Drawable drawable = icons.getDrawable(0); TypedArray colors = res.obtainTypedArray(R.array.colors); int color = colors.getColor(0,0); Styleable Attribute syntax: file location: res/ compiled resource datatype: Resource pointer to a Menu (or subclass) resource. resource reference: Java: R. XML: elements and attributes: Valid attributes: example: XML file saved at res/: Java code : see also: -- Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates. Last updated 2026-05-18 UTC. [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-05-18 UTC."],[],[]] X Follow @AndroidDev on X YouTube Check out Android Developers on YouTube LinkedIn Connect with the Android Developers community on LinkedIn More Android Android Android for Enterprise Security Source News Blog Podcasts Discover Gaming Machine Learning Health & Fitness Camera & Media Privacy 5G Android Devices Large screens Wear OS ChromeOS devices Android for cars Android TV Releases Android 17 Android 16 Android 15 Android 14 Android 13 Android 12 Android 11 Documentation and Downloads Android Studio guide Developers guides API reference Download Studio Android NDK Support Report platform bug Report documentation bug Google Play support Join research studies Android Chrome Firebase Google Cloud Platform All products Privacy License Brand guidelines Manage cookies Get news and tips by email Subscribe English Deutsch Español – América Latina Français Indonesia Italiano Polski Português – Brasil Tiếng Việt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文 – 简体 中文 – 繁體 日本語 한국어