How do draw italic text on Android canvas?

Swarnendu Paul picture Swarnendu Paul · Jul 26, 2013 · Viewed 10.8k times · Source

In my app I am drawing text on Android Canvas;

Now to support underline and bold I am taking help of paint object;

 Paint paint = new Paint();   

 paint.setUnderlineText(true); 
 paint.setFakeBoldText(true);

 paint.setColor(color);
 paint.setTextSize (font_size);
 canvas_obj.drawText(text,x,y,paint);

With this code I am getting bold and underlined text;

I also like to make it italic,

I am developing app for android 2.2 onwards.

how to do it?

Edit:

I am setting Typeface object created with an external font file to support external font; For Italic I am using following code

paint.setTypeface(Typeface.create(external_font_type_face,Typeface.ITALIC));

This also not working, Tested on Samsung Galaxy Ace (android 2.2)

Answer

TN888 picture TN888 · Jul 26, 2013

You can use that method :

paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC));

It's working for me.