简体   繁体   English

Android:将不同的格式样式应用于一个textview

[英]Android: different formatting styles applied to one textview

I have one text view in my XML and in that text view i have a large number of text which i would like to apply different formatting styles to different text in the text view. 我在XML中有一个文本视图,在那个文本视图中我有大量的文本,我想对文本视图中的不同文本应用不同的格式设置样式。 Like center alignment,different fonts,different font size and underline.How do I achieve this? 像居中对齐,不同的字体,不同的字体大小和下划线。如何实现此目的? My sample code is below: 我的示例代码如下:

String [] item = {"Chicken BBQ bacon \n \n BBQ Chicken,Bacon,Sweet Corn,Onion \n \n <b>Regular</b> sh 500 \n \n Medium sh 700 \n \n Large sh 900 \n \n","Chicken and Mushroom \n \n chicken,mushroom \n \n Regular  Medium  Large \n \n sh500 sh700 sh900"}

description.setText(Html.fromHtml(item[x]));

You should use SpannableString 您应该使用SpannableString
Take a look for an example here: 在这里看看一个例子:
Different font size of strings in the same TextView 同一TextView中字符串的不同字体大小
Or using HTML tags, take a look: 或使用HTML标签,看看:
http://daniel-codes.blogspot.co.il/2011/04/html-in-textviews.html http://daniel-codes.blogspot.co.il/2011/04/html-in-textviews.html

Well I found an interesting library regarding Textview 好吧,我找到了一个有趣的关于Textview的库

advanced android Textview 先进的android Textview

You can add various Styles,arbitary fractions,Spannable Strings,Alignment Span,Rainbow Span,Unicode with System fonts,Custom Fonts etc. 您可以添加各种样式,任意分数,跨度字符串,对齐跨度,彩虹跨度,带有系统字体的Unicode,自定义字体等。

Hope it helps to enhance your creativity more!!Happy Coding!! 希望它可以帮助您进一步提高创造力!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM