[英]Custom Font Android Studio With Draw?
I created an "assets" folder and I created a "fonts" folder inside. 我创建了一个“资产”文件夹,并在其中创建了一个“字体”文件夹。 The custom font is called "dshift.tff".
自定义字体称为“ dshift.tff”。 I have my main screen running in a loop with updates and need to create a display with external font.
我的主屏幕与更新循环运行,需要创建带有外部字体的显示器。
public void drawText(Canvas canvas) {
Paint paint = new Paint();
//Tell me what to do here please
}
This method is getting called by 该方法被调用
public void draw(Canvas canvas)
{
super.draw(canvas);
//... rest of my code with no more declarations
}
Create the typeface elsewhere such that it is accessible in your drawText
, as you do not wish to do this every time during rendering - 在其他位置创建字体,以便在
drawText
可以访问它,因为您不希望在渲染过程中每次都这样做-
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Kokila.ttf");
In your drawText, create a Paint
object and set its typeface 在您的drawText中,创建一个
Paint
对象并设置其字体
Paint paint = new Paint();
paint.setTypeface (type);
Then draw text using the paint object. 然后使用绘画对象绘制文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.