What is the meaning of curly brackets { } in string resource file of android?

Issue

In fragments navigation codelabs I found a use of curly braces {} inside a string tag in string.xml

<string name"word_list_fragment_label">Words That Start With {letter}</string>

On running the app {letter} is replaced with whatever letter button user presses. What does {letter} refer to?

Solution

{x} gets replaced with a value x from navigation arguments.

This is a “new” feature of androidx-navigation 1.0.0 alpha 08:

Destination labels, when used with NavigationUI methods, will now automatically replace {argName} instances in your android:label with the correct argument b/80267266

Source: https://developer.android.com/jetpack/androidx/releases/navigation (page fragment names duplicated so cannot link directly to that release)

Android issue tracker: https://issuetracker.google.com/issues/80267266

Answered By – laalto

Leave a Comment