开发者

Canvas.drawText("+5") Doesn't show "+" symbol at all in Android? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I am sure this has something to do with needing an escape character or something - but I cannot figure it out. When I try to draw +5 to my canvas the + sign never shows up - I noly see the 5.

Anyone know of a way to draw special characters like this to the canvas?

Thanks!

Here is me code that compiles but does not show the "+":

    private void doDraw(Canvas canvas) {
       //oth开发者_开发百科er misc canvas.draw(...) calls

       canvas.drawText("+5", xPos, yPos, bonusScorePaint);
}

Apparently

canvas.drawText("\+5", xPos, yPos, bonusScorePaint);

is not a valid escape sequence so this doesn't compile.


You answered your own question. Yes you need a "\" in front of the "+".


Turns out it was my TypeFace. Not sure why, I am using a custom font but the + sign exists in this font.


Here is the code that I have:

ImageView img = (ImageView)findViewById(R.id.img);
Bitmap bmp = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
Paint p = new Paint();
p.setColor(Color.WHITE);
c.drawText("+5", 20, 20, p);
img.setImageBitmap(bmp);

My only thoughts are that it could be the color of your paint object or the position of the object.


As Konrad Rudolph said, try \\+

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜