【问题标题】:Custom Fonts are not Showing Properly With Only One Color Showing自定义字体无法正确显示,仅显示一种颜色
【发布时间】:2016-05-04 09:59:08
【问题描述】:

我最近在使用多色字体时遇到了一些麻烦。我使用的字体使用了白色和黑色,但由于某种原因,只显示了黑色,而内部的白色没有显示。我做错了什么,或者有没有办法让字体颜色在那里?谢谢你。这是代码--

Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/editundo.otf");

//crating color fill and adding in font to the paint and setting the color fill white and text size 150
Paint paint = new Paint();
paint.setTypeface(tf);
paint.setTextSize(150);

// do other setup on Paint object
// Draw all the text stuff
//if the screen has not been tapped touch screen to start
if (f == 0) {
    canvas.drawText("Tap to Start", MainActivity.screenWidth / 4, MainActivity.screenHeight / 2, paint);
}

//Setting text as 40 size and draw the score text
paint.setTextSize(40);
canvas.drawText("Score: " + score, 10, 50, paint);
canvas.drawText("High Score: " + HighScore, 10, 120, paint);
paint.setTextSize(35);
canvas.drawText("Car Tokens: " + coinz, MainActivity.screenWidth*7/9+MainActivity.screenWidth*2/100, 50, paint);

另外,我使用的字体是 Mouser Outline 字体,我将它用作 .otf 和 .ttf。字体的链接在这里——http://fontzone.net/font-details/mouser-outline

再次感谢您的帮助。

【问题讨论】:

  • 您需要做的就是在您的绘画对象上设置颜色:paint.setColor(Color.WHITE)
  • 我试过了。它没有用,我也想要内部是白色的。

标签: java android fonts


【解决方案1】:

Colorful Font 不能作为 java.awt 工作。字体仅支持多种特定文本/设置,如粗体、大小、斜体等...

我所知道的将字体写入屏幕的唯一方法是将每个字符保存为图像......

如下所述:

Java - Multi-colored text

此处显示字体的限制:

https://docs.oracle.com/javase/7/docs/api/java/awt/Font.html

【讨论】:

  • 等等。您是否建议使用位图字体?
  • 我明白你的意思,谢谢,但是显示的链接没有实际答案。
  • 没关系。我只是指出了转换的方向。 android 的实现可能会有点不同
猜你喜欢
  • 2011-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-06
  • 1970-01-01
  • 1970-01-01
  • 2019-07-15
  • 1970-01-01
相关资源
最近更新 更多