Use string with arguments with tools:text

Viewed 275

I have a string with arguments (for example <string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>). I know, that I can use it at my code with String.format(res.getString(R.string.welcome_messages), username, mailCount); and I will get a full message with username and count. But can I preview it in .xml layout, using tools:text? or any other tools instrument?

1 Answers

No you can't.

According to the documentation of TextView and the Tools-Attribute there is no way to replace the String placeholders in XML.

I was researching this a while ago and ended up hard-coding the text via tools:text. As this only affects design previews I think that hardcoding the text is okay in this case.

Related