Stay organized with collections
Save and categorize content based on your preferences.
Get started
Learn how to get your development environment ready to work with the Data
Binding Library, including support for data binding code in Android Studio.
The Data Binding Library offers both flexibility and broad
compatibility—it's a support library, so you can use it with devices
running Android 4.0 (API level 14) or higher.
We recommend using the latest Android Gradle plugin in your project.
However, data binding is supported on version 1.5.0 and higher. For more
information, see how to update the Android Gradle
plugin.
Build environment
To get started with data binding, download the library from the Support
Repository in the Android SDK manager. For more information, see Update the
IDE and SDK Tools.
To configure your app to use data binding, enable the dataBinding build option
in your build.gradle file in the app module, as shown in the following
example:
android{
...
buildFeatures{
dataBindingtrue
}
}
Android Studio support for data binding
Android Studio supports many of the editing features for data binding code. For
example, it supports the following features for data binding expressions:
The Preview pane in the Layout Editor displays the default value of data
binding expressions, if provided. For example, the Preview pane displays the
my_default value on the TextView widget declared in the following example:
If you need to display a default value only during the design phase of your
project, you can use tools attributes instead of default expression values, as
described in the Tools attributes reference.
Additional resources
To learn more about data binding, consult the following
additional resources.
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 2025-02-10 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 2025-02-10 UTC."],[],[],null,["# App Architecture: UI Layer - Get Started - Android Developers\n\nGet started\n===========\n\nLearn how to get your development environment ready to work with the Data\nBinding Library, including support for data binding code in Android Studio.\n\nThe Data Binding Library offers both flexibility and broad\ncompatibility---it's a support library, so you can use it with devices\nrunning Android 4.0 (API level 14) or higher.\n\nWe recommend using the latest Android Gradle plugin in your project.\nHowever, data binding is supported on version 1.5.0 and higher. For more\ninformation, see how to [update the Android Gradle\nplugin](/studio/releases/gradle-plugin#updating-plugin).\n\nBuild environment\n-----------------\n\nTo get started with data binding, download the library from the **Support\nRepository** in the Android SDK manager. For more information, see [Update the\nIDE and SDK Tools](/studio/intro/update).\n\nTo configure your app to use data binding, enable the `dataBinding` build option\nin your `build.gradle` file in the app module, as shown in the following\nexample: \n\n android {\n ...\n buildFeatures {\n dataBinding true\n }\n }\n\n| **Note:** You must configure data binding for app modules that depend on libraries that use data binding, even if the app module doesn't directly use data binding.\n\nAndroid Studio support for data binding\n---------------------------------------\n\nAndroid Studio supports many of the editing features for data binding code. For\nexample, it supports the following features for data binding expressions:\n\n- Syntax highlighting\n- Flagging of expression language syntax errors\n- XML code completion\n- References, including [navigation](https://www.jetbrains.com/help/idea/2017.1/navigation-in-source-code.html)---such as navigating to a declaration---and [quick documentation](https://www.jetbrains.com/help/idea/2017.1/viewing-inline-documentation.html)\n\n| **Caution:** Arrays and a [generic\n| type](https://docs.oracle.com/javase/tutorial/java/generics/types.html), such as the [`Observable`](/reference/androidx/databinding/Observable) interface, might incorrectly display errors.\n\nThe **Preview** pane in the **Layout Editor** displays the default value of data\nbinding expressions, if provided. For example, the **Preview** pane displays the\n`my_default` value on the `TextView` widget declared in the following example: \n\n \u003cTextView android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:text=\"@{user.firstName, default=my_default}\"/\u003e\n\nIf you need to display a default value only during the design phase of your\nproject, you can use `tools` attributes instead of default expression values, as\ndescribed in the [Tools attributes reference](/studio/write/tool-attributes).\n\nAdditional resources\n--------------------\n\nTo learn more about data binding, consult the following\nadditional resources.\n\n- [Android Data Binding Library samples](https://github.com/android/databinding-samples)\n\n\u003c!-- --\u003e\n\n- [Data Binding in Android codelab](https://codelabs.developers.google.com/codelabs/android-databinding)\n\n\u003c!-- --\u003e\n\n- [Data Binding --- lessons learnt](https://medium.com/androiddevelopers/data-binding-lessons-learnt-4fd16576b719)\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Work with observable data objects](/topic/libraries/data-binding/observability)\n- [View binding](/topic/libraries/view-binding)\n- [Paging 2 library overview](/topic/libraries/architecture/paging)"]]