Font Awesome不支持直接字符串输入

时间:2017-08-18 06:18:31

标签: android textview font-awesome

我想在我的应用程序中将字体设置为一个文本视图。 我使用它如下,它工作正常:

 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));

但是当我想像鳕鱼一样使用它时,它不起作用:

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

3 个答案:

答案 0 :(得分:1)

试试这个

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(""));

答案 1 :(得分:0)

您可以尝试使用以下代码

awesomeButton.setText(Html.fromHtml(""));

答案 2 :(得分:0)

你可以试试这段代码,我觉得这个可以帮助你。

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);