15

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)

Scarecrow
  • 4,057
  • 3
  • 30
  • 56

2 Answers2

30

You can use that method :

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

It's working for me.

TN888
  • 7,659
  • 9
  • 48
  • 84
  • I am already using a Typeface object( created with an external font file, ) in paint ; I am developing app for android 2.2 onwards – Scarecrow Jul 26 '13 at 10:24
  • @Swarnendu Typeface has been implemented in Android 1.5 – TN888 Jul 26 '13 at 10:25
  • @ Ty221 Unfortunately it is not working, setting typeface to paint object is replacing previously set typrface object to the paint object(which was set to support external font ); so neither I am getting the external font support nor italic text with default font.. :-( – Scarecrow Jul 26 '13 at 10:35
  • I don't know other way (Google also don't know) – TN888 Jul 26 '13 at 10:36
2

Use this:

paint.setTextSkewX(-0.25f);
Gaurav Kumar
  • 834
  • 1
  • 6
  • 14
  • 1
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Isma Dec 08 '17 at 10:24