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?
CodePudding user response:
{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
CodePudding user response:
Follow this steps:
step 1: add this string in your XML file
<string name="word_list_fragment_label">Words That Start With { %s }</string>
step 2: in your activity perform set text like this :
yourTextView.text = String.format(getString(R.string.word_list_fragment_label),"Your text that you want to set")