Search code examples
androiddrawtext

canvas draw text- cant get strings


String str = new String();
str = "111";
x = width / 2;
y = Math.round(height / 1.3);

while (pressed != true){
    if (!holder.getSurface().isValid()) 
        continue;
    Canvas c = holder.lockCanvas();
    c.drawBitmap(galaxy, 0, 0, null);
    c.drawBitmap(player, x - (player.getWidth() / 2), y - (player.getHeight() / 2), null);
    c.drawText("111", c.getWidth() / 12, c.getHeight() / 15, timerpaint);

    holder.unlockCanvasAndPost(c);
}

I tried to put the str insted "111" in the "drawText" function, and it didn't write anything, I'm not sure why.

Thanks!


Solution

  • Replace this:

    String str = new String(); 
    str = "111";
    

    With this:

    String str = " 111";
    

    Hope my answer helps.