android - 绘制具有特定文本外观的文本

标签 android paint

如何绘制具有特定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/

相关文章:

Android从浏览器获取url

Java - 游戏在绘制方法中循环还是在单独线程的 while 循环中循环?

java - 画图程序麻烦java

android - 对 Assets 文件夹使用限定符

java - Kotlin 中的 public static void main

Delphi SelectClipRGN 隐藏绘制位图

HTML5 canvas 在背景图像上绘制缩放

java - 每次我尝试更改油漆的属性(厚度或颜色)时,它都会更改 Canvas 上已有的现有油漆(android)(java)

java - 重新启动测试应用程序时 Jenkins 停止工作

android 使布局在软键盘打开时可滚动,但不向上移动