Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textview fromHtml bold tag not properly shown

I am using fromHtml for some words, but it not properly shown.Sorry my bad english.

        Typeface tfArial = Typeface.createFromAsset(getAssets(), "arialtur.otf");

    String yazi="Deneme "+"<strong>"+"must be bold"+"</strong>"+" kayıt.";
    Spanned text1 = Html.fromHtml(yazi);
    TextView aa= (TextView) findViewById(R.id.metin1);
    TextView ab= (TextView) findViewById(R.id.metin2);

    aa.setText(text1);
    aa.setTypeface(tfArial);        
    ab.setText("Non arial font");

screenshot http://hizliresim.com/rd4gkV

like image 446
manowar_manowar Avatar asked Oct 27 '14 13:10

manowar_manowar


2 Answers

In case of <b> tag in resourses string you could wrap text in <![CDATA[ and ]]>, i.e.:

<string name="textWithBold"><![CDATA[<b>BoldText</b>]]></string>

Then you could get and show it so:

textView.setText(Html.fromHtml(getString(R.string.textWithBold)));
like image 118
mohax Avatar answered Nov 09 '22 19:11

mohax


<strong> HTML tag is not a "styling" tag. It's here only to indicates that the content is important. The default style of the <strong> relies on the web engine implementation.

You can have some information on these two links :

  • http://www.w3schools.com/tags/tag_strong.asp
  • What's the difference between <b> and <strong>, <i> and <em>?

Try to use <b> instead of <strong> if you want a bold text.

like image 40
mithrop Avatar answered Nov 09 '22 17:11

mithrop