8

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

manowar_manowar
  • 1,215
  • 2
  • 16
  • 32

4 Answers4

14

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)));
mohax
  • 4,435
  • 2
  • 38
  • 85
3

<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 :

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

Community
  • 1
  • 1
mithrop
  • 3,283
  • 2
  • 21
  • 40
1

you can do this several ways like

Typeface tfArial =Typeface.createFromAsset(getAssets(),"arialtur.otf");
String yazi="Deneme <strong> must be bold </strong> kayıt.";
 // OR  String yazi="Deneme <b> must be bold </b> kayıt.";

TextView aa= (TextView) findViewById(R.id.metin1);
TextView ab= (TextView) findViewById(R.id.metin2);
aa.setText(Html.fromHtml(yazi));
aa.setTypeface(tfArial); 
 //OR  aa.setTypeface(tfArial,Typeface.BOLD);      
ab.setText("Non arial font");

Example :

using strong tag

Deneme must be bold kayıt.

using b tag

Deneme must be bold kayıt

MilapTank
  • 9,988
  • 7
  • 38
  • 53
1

Try this.

String message ="Deneme "+"<b>"+"must be bold"+"</b>"+" kayıt.";
aa.setText(Html.fromHtml(message));

You can also do same thing from XML by useing of HTML tag

samsad
  • 1,241
  • 1
  • 10
  • 15