Fragmentary knowledge records

1, String placeholder

<string name="welcome_messages">Hello, %2$s! You have %1$s %1$s new messages.</string>

String textStr = getResources().getString(R.string.welcome_messages,  "我是", "小明");
text.setText(textStr);

The results :! Hello, Xiao Ming You have me is that I'm new messages.

<string name="welcome_messages">Hello, %s! You have %s s new messages.%s</string>

. String textStr = getResources () getString (R.string.welcome_messages, " I am", "Xiao Ming", "Tomorrow");
text.setText (textStr);

The results : Hello, I'm Bob You have new messages tomorrow!.

getText (int resId) method and the getString (int resId) (, int resId "", ""), getResources (). the getString difference method

getText : return CharSequence

getString:内部getResources().getString

If the string is html style

String text = "<b> bold </ b>" normal display

String text = getString (R.string.welcome); // will automatically remove the label, you need to manually escape, otherwise the display is not normal

 

Published 49 original articles · won praise 2 · Views 8596

Guess you like

Origin blog.csdn.net/yangjunjin/article/details/104650206