Is it possible to have texts with different sizes, font-types or styles in the same TextView
?
Something like this:
| myLogin logout |
You can do this using:
textView.setText(Html.fromHtml("<b>myLogin</b> <i>logout</i>"));
For more options, look into SpannableString
: Link
With SpannableString
, you can apply multiple formatting to a single string.
This article will be very helpful to you: Rich-Style Formatting of an Android TextView
For anyone who wants to do this without the HTML formatting , use a SpannableString.
As in :
SpannableString styledString = new SpannableString("myLogin logout");
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, 7, 0);
styledString.setSpan(new StyleSpan(Typeface.ITALIC), 8, 14, 0);
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText(styledString);
More examples can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With