自定义尺寸的使用Spannable斜体字体 [英] Custom sized italic Font using Spannable

查看:239
本文介绍了自定义尺寸的使用Spannable斜体字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有如下code:

String s = message + "\n" + date;
Spannable f = Spannable.Factory.getInstance().newSpannable(s);
f.setSpan(new ForegroundColorSpan(Color.BLUE), 0, message.length(), 0);
f.setSpan(new ForegroundColorSpan(Color.RED), message.length() + 1, s.length(), 0);

textView.setText(f);

这code正常工作为TextView中设置diffent颜色。但我需要另一个特点 - 我喜欢约会得到了字体和斜体的更小的尺寸。我怎样才能做到这一点?

This code works fine for setting up diffent colors for textView. But I need another feature - I'd like that "date" has got smaller size of font and italic typeface. How can I achieve that?

推荐答案

勾选此

<一个href=\"http://stackoverflow.com/questions/16335178/different-size-of-strings-in-the-same-textview/16335416#16335416\">Different在相同的TextView 字符串大小

请尝试以下

String title="My Custom Text!";  
TextView tv = (TextView) findViewById(R.id.some_id);
SpannableString ss1=  new SpannableString(title);
ss1.setSpan(new StyleSpan(Typeface.ITALIC), 0, ss1.length(), 0);
ss1.setSpan(new RelativeSizeSpan(2f), 0, ss1.length, 0); 
tv.setText(ss1);

有关更多造型

http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring

这篇关于自定义尺寸的使用Spannable斜体字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆