android: string format specify bold

后端 未结 7 658
半阙折子戏
半阙折子戏 2021-01-05 05:05

I have a string defined in string.xml like

Title: %1$s 

which is formatted us

7条回答
  •  时光取名叫无心
    2021-01-05 05:35

    Actually, many of the answers are obsolete. After researching by myself, what I've found out that the best answer is one by @Wahib. Here's the improved version:

    Define the string resource as a:

    Hey, <b>this is bold</b> text
    

    Use the resource like this:

    String text = getResources().getString(R.string.styled_text);
    CharSequence styledText = HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY);
    textview.setText(styledText);
    

    Here's the result:

提交回复
热议问题