自定义字体和粗体样式文本 [英] Text with custom font and bold style

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

问题描述

我开发的应用程序。我使用自定义字体。 .TTF文件自定义的文本视图字体。我用code为:

I am developing an application. I am using custom font. ".ttf" file to customize font of text view. I used the code as :

Typeface tfArchitectsDaughter = Typeface.createFromAsset(getAssets(), "fonts/ArchitectsDaughter.ttf");
textview.setTypeface(tfArchitectsDaughter);

现在需要的是:我想使文本定制正如我上面也做在.java文件的样式为粗体

Now the need is : i want to make the text customize as i done above as well as the style as BOLD in .java file.

如何做到这一点请建议。什么其他的样式或定制可以在字体进行请建议。

How to do this please suggest. And what other styles or customization can be done on font please suggest.

感谢你。

推荐答案

使用一个SpannableString。 也看看这个教程。<一个href="http://blog.stylingandroid.com/archives/177">http://blog.stylingandroid.com/archives/177.

Use a SpannableString. Also have a look at this tutorial.http://blog.stylingandroid.com/archives/177.

String tempString="Copyright";
TextView text=(TextView)findViewById(R.id.text);
SpannableString spanString = new SpannableString(tempString);
spanString.setSpan(new UnderlineSpan(), 0, spanString.length(), 0);
spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString.length(), 0);
spanString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spanString.length(), 0);
text.setText(spanString);

您还可以在TextView中使用不同的文本颜色的。

You can also use different color for text's in textview.

SpannableString text = new SpannableString("Lorem ipsum dolor sit amet");  
// make "Lorem" (characters 0 to 5) red  
text.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);  
textView.setText(text, BufferType.SPANNABLE);

<一个href="http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring">http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring.链接为您提供了使用spannable线造型的例子。

http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring. The link gives you more example of styling using spannable string.

这篇关于自定义字体和粗体样式文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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