Canvas.drawText("+5") Doesn't show "+" symbol at all in Android? [closed]
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 \\+
精彩评论