Ehsan
Ehsan

Reputation: 2781

Font Awesome doesn't work with direct string input

I want to set font awesome to one text view in my application. I used it like below and it works fine:

 Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome/fonts/fontawesome-webfont.ttf" );
 TextView awesomeButton = (TextView)findViewById(R.id.awesome_button);
 awesomeButton.setTypeface(font);
 awesomeButton.setText(MainActivity.this.getString(R.string.heart));

But when i want to use it like below cod, It doesn't work:

Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome/fonts/fontawesome-webfont.ttf" );
TextView awesomeButton = (TextView)findViewById(R.id.awesome_button);
awesomeButton.setTypeface(font);
awesomeButton.setText("");

Upvotes: 2

Views: 135

Answers (3)

AskNilesh
AskNilesh

Reputation: 69689

try this

Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome/fonts/fontawesome-webfont.ttf" );
TextView awesomeButton = (TextView)findViewById(R.id.awesome_button);
awesomeButton.setTypeface(font);
awesomeButton.setText(Html.fromHtml(""));

Upvotes: 1

Kishan Donga
Kishan Donga

Reputation: 3193

you can try this code I think this one help you.

Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome/fonts/fontawesome-webfont.ttf" );
TextView awesomeButton = (TextView)findViewById(R.id.awesome_button);
awesomeButton.setTypeface(font);
String tmpHtml = "<html>&#x2665;</html>";
String htmlTextStr = Html.fromHtml(tmpHtml).toString();
awesomeButton.setText(htmlTextStr);

Upvotes: 0

Girish H
Girish H

Reputation: 79

Can you try with below code

awesomeButton.setText(Html.fromHtml("&#xf076;"));

Upvotes: 0

Related Questions