ksome ksome - 1 year ago 160
Android Question

Draw fontawesome to bitmap

I want to draw an icon from fontawesome to a notification view in android. To do so I tried to draw this icon to a Bitmap, to set the typeface, and then set the Bitmap in the notification view.

I use this code:

Bitmap myBitmap = Bitmap.createBitmap(100, 50, Bitmap.Config.ARGB_8888);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface typeface = Typeface.createFromAsset(getApplicationContext().getAssets(),"fonts/fontawesome-webfont.ttf");
myCanvas.drawText("", 0, 20, paint);
notificationView.setImageViewBitmap(R.id.activity, myBitmap);

But all it shows is
and no icon. In other contexts the fontawesome works just fine.

Answer Source

 is an HTML-style entity reference. Most places in Android will just treat that as a sequence of characters with no particular meaning.

In your case, the simplest solution is to use Java Unicode string literal syntax, replacing the &#x with \u and removing the ;, giving you "\uf29d".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download