仅显示一种颜色时,自定义字体无法正常显示

时间:2016-05-04 01:50:52

标签: java android fonts

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

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

再次感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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

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

如下所述:

Java - Multi-colored text

这里显示了字体的限制:

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