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)
Format Text To bold text, tap the Bold icon [3]. To italicize text, tap the Italics icon [4]. To underline text, tap the Underline icon [5]. To stop using bold, italics, or underline formatting, tap the Bold, Italics, or Underline icon again.
Double tap the text you want to format. Tap Format, then choose a formatting option like bolding, italics, or changing the font color.
android:textStyle attribute is the first and one of the best way to make the text in TextView bold. just use “bold”. If you want to use bold and italic. Use pipeline symbol “|” .
You can use that method :
paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC));
It's working for me.
Use this:
paint.setTextSkewX(-0.25f);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With