I have a string defined in string.xml
like
Title: %1$s
which is formatted us
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:
<string name="styled_text">Hey, <b>this is bold</b> text</string>
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:
You can use HTML markup like "<b>BOLD</b> other text ..."
.
See this Google resource for more information.
Now, it is reasonably supported by Android.
you can define the string in xml as <string name="text_to_show">Hey <b>This is in bold</b>
Then in code, use this to convert to CharSequence and then use it for e.g in TextView
String text = getResources().getString(R.string.text-to_show);
CharSequence styledText = Html.fromHtml(text);
textview.setText(styledText);
Now, it is reasonably supported by Android.
I have already given answer to this how to add styling within a string
You have to style your string in the TextView in which in is displayed. See this link
You can do it like,
textView.setText(Html.fromHtml("<b>Title</b>: Text"));
If you have text in dynamic way..
And to define formatings in Strings.xml you can do like,
<string name="text1">This text uses <b>bold</b> and <i>italics</i>
by using inline tags such as <b> within the string file.</string>
see This Link