可在 android 上用于 textView [英] spannable on android for textView
本文介绍了可在 android 上用于 textView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Tweet o = tweets.get(position);
TextView tt = (TextView) v.findViewById(R.id.toptext);
//TextView bt = (TextView) v.findViewById(R.id.bottomtext);
EditText bt =(EditText)findViewById(R.id.bottomtext);
bt.setText(o.author);
Spannable spn = (Spannable) bt.getText();
spn.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC)
, 0, 100, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//bt.setText(o.author);
tt.setText(o.content);
我正在我的 Android 应用程序中设置 Twitter 数据.我想使用 Spannable 将字体设为粗体和斜体,但它不起作用,并出现错误.我该怎么做?
I'm setting twitter data in my Android application. I want to make the font bold and italic using Spannable but it does not work, giving an error. How can I do it?
推荐答案
我想用 spannable 使字体变粗和斜体
I want to make the font bold and ıtalic with spannable
为此,您需要将 o.content
文本设为 SpannableString
然后将其设置为 TextView :
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);
您还可以使用 Html.fromHtml 在 textview 中制作文本粗体和斜体:
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>"));
这篇关于可在 android 上用于 textView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文