简体   繁体   中英

Changing the text size of text in strings.xml

I was wondering if there was a way to alter the size of parts of a String in strings.xml . In my Java code I call

builder.setMessage(R.string.my_string)

I am wondering if there is a way to set the text size, similarly to how you can set the text to bold by doing this:

<string name="my_string"><b>My String</b></string>

You can make use of Html.fromHtml("your html string"), to do any style you want in HTML and then show it in the textview as shown below:

Spanned htmlText = Html.fromHtml(getString(R.string.yourStringResource));
yourTextView.setText(htmlText, TextView.BufferType.SPANNABLE);

And the XML string.xml, must have the string declared as shown below:

<string name="yourStringResource"><![CDATA[BLA BLA BLA BLA <br/> BLABA <font color="blue">COLORED HTML</font>]]></string>

Regards!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM