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,但它不工作,给了一个错误。我该怎么做呢?
发布于 2013-02-13 03:40:32
我想使字体粗体和ı
与spannable
为此,u需要将o.content文本设置为SpannableString,然后将其设置为TextView:
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 :您还可以使用Html.fromHtml在文本视图中设置文本粗体和斜体,如下所示:
tt.setText(Html.fromHtml("<strong><em>"+o.content+"</em></strong>"));发布于 2015-08-22 07:27:06
创建要设置到TextView中的spannable text bold和italic的简单方法是使用方法Html.fromHtml()
并使用html元素<b>和<i>
myTextView.setText(Html.fromHtml("<b><i>my text bold and italic!</i></b>"));或html元素<strong>和<em>
myTextView.setText(Html.fromHtml("<strong><em>my text bold and italic!</em></strong>"));发布于 2020-06-12 23:50:00
SpannableString hint = new SpannableString(o.content.toString());字体大小
hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);字体系列
hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);斜体
hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, s.length(), 0);颜色
hint.setSpan(new ForegroundColorSpan(Color.GRAY), 0, hint.length(), 0);粗体
hint.setSpan(new StyleSpan(Typeface.BOLD), 0, hint.length(), 0);参考链接:https://www.programcreek.com/java-api-examples/index.php?api=android.text.style.RelativeSizeSpan
https://stackoverflow.com/questions/14840247
复制相似问题