How to draw text with a specific TextAppearance
?
Here is my code.
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setFakeBoldText(false);
paint.setTextSize(textSize);
// TODO: set the style of the text to a specific TextAppearance. E.g. @android:style/TextAppearance.DeviceDefault.Large.Inverse
canvas.drawText(context.getResources().getString(R.string.myString), textOffsetX, textOffsetY, paint);
I have looked at TypeFace
object, but I am not sure how to create a TypeFace from a TextAppearance.
A coworker gave me a solution that uses a TextView
as the a bridge for the TextAppearance
TextView textView = new TextView(context);
textView.setTextAppearance(context, android.R.style.TextAppearance.DeviceDefault.Large);
paint.setColor(textView.getCurrentTextColor());
paint.setTextSize(textView.getTextSize());
paint.setTypeface(textView.getTypeface());
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