如何绘制具有特定TextAppearance
的文本?
这是我的代码。
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);
我查看了 TypeFace
对象,但我不确定如何从 TextAppearance 创建 TypeFace。
最佳答案
一位同事给了我一个解决方案,它使用 TextView
作为 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());
关于android - 绘制具有特定文本外观的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26661371/