TextView With Different Fonts And Styles?
Is it possible to have texts with different sizes, font-types or styles in the same TextView ? Something like this: | myLogin logout |
Solution 1:
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
Solution 2:
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 : http://androidcocktail.blogspot.in/2014/03/android-spannablestring-example.html
Solution 3:
Unless you make a custom TextView, no. Consider using two different TextViews if you do not want to create a custom TextView.
Post a Comment for "TextView With Different Fonts And Styles?"