The Paint.setTypeface is not working for italic or I'm doing something the wrong way. I can create normal, bold, monospace, and serif text, but I can't create italic text. It always looks normal (or in the case of bold-italic, it looks bold).
//This will appear monospace
paint.setTypeface(Typeface.MONOSPACE);
canvas.drawText("foo", 10, 10, paint);
//This will appear serif
paint.setTypeface(Typeface.SERIF);
canvas.drawText("foo", 10, 10, paint);
//This will appear bold
paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
canvas.drawText("foo", 10, 10, paint);
//This will NOT appear italic <=== PROBLEM
paint.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));
canvas.drawText("foo", 10, 10, paint);
// This isn't working either <=== PROBLEM
paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC));
So now the question: is there a known workaround for this? My simple goal is to draw some words with italic style...
After experiencing the same difficulty, I found the solution by fishing around in theTextView
source code. Try this:
paint.setTextSkewX(-0.25f);