spannable on android for textView

邮差的信 提交于 2019-11-27 07:34:06

I want to make the font bold and ıtalic with spannable

for this u will need to make o.content text as SpannableString then set it to TextView as :

SpannableString spannablecontent=new SpannableString(o.content.toString());
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 
                         0,spannablecontent.length(), 0);
// set Text here
tt.setText(spannablecontent);

EDIT : you can also use Html.fromHtml for making text Bold and Italic in textview as :

tt.setText(Html.fromHtml("<strong><em>"+o.content+"</em></strong>"));

The easy way to create a spannable text bold and italic to set into your TextView is using the method Html.fromHtml():

and using the html elements <b> and <i>

myTextView.setText(Html.fromHtml("<b><i>my text bold and italic!</i></b>"));

or the html elements <strong> and <em>

   myTextView.setText(Html.fromHtml("<strong><em>my text bold and italic!</em></strong>"));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!