Skip to main content

Accessing String Resources with Placeholders Using Data Binding in Layout XML

Table of Contents

This article was translated from Japanese by Claude Code.

As described in the official reference:

<string name="self_introduction">My name is %1$s</string>

Suppose you have a string resource defined like this. If you want to bind it to a TextView’s text field using Data Binding in Layout XML, previously it seemed like only this way of writing worked:

android:text="@{String.format(@string/self_introduction, user.name)}"

But upon re-checking, you can also write:

android:text="@{@string/self_introduction(user.name)}"

Just a note.

Reference Links#