0

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. 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]));
lorrainemutheu
  • 115
  • 1
  • 17
  • Possible duplicate of [Is it possible to have multiple styles inside a TextView?](http://stackoverflow.com/questions/1529068/is-it-possible-to-have-multiple-styles-inside-a-textview) – Nongthonbam Tonthoi Jun 08 '16 at 09:08

2 Answers2

0

You should use SpannableString
Take a look for an example here:
Different font size of strings in the same TextView
Or using HTML tags, take a look:
http://daniel-codes.blogspot.co.il/2011/04/html-in-textviews.html

Community
  • 1
  • 1
Benny
  • 2,233
  • 1
  • 22
  • 27
  • the problem with spannable string is that i will have to find position of characters in a word and i have like 100 words inside my textview. Is there a simpler way to do it.The string i posted above is just a sample not the whole text. – lorrainemutheu Jun 11 '16 at 10:11
0

Well I found an interesting library regarding Textview

advanced android Textview

You can add various Styles,arbitary fractions,Spannable Strings,Alignment Span,Rainbow Span,Unicode with System fonts,Custom Fonts etc.

Hope it helps to enhance your creativity more!!Happy Coding!!

PN10
  • 1,888
  • 3
  • 23
  • 34
  • The link you sent above is not working. Could you please give me another. – lorrainemutheu Jun 11 '16 at 10:12
  • well i clicked on above link in my case its working..Any way here is link to official github library https://github.com/chiuki/advanced-textview an above link i have provided is of Companion app for demostrating how to use it....If it helps u please acknowledge my answer by accepting or by upvoting it..Happy coding buddy. – PN10 Jun 11 '16 at 10:35
  • I have checked out the link and it works. I have found very useful information which i highly appreciate but none seems to answer my question.Thanks anyway. – lorrainemutheu Jun 12 '16 at 17:31