Android Canvas.drawText not showing

I have a custom view that draws several different things on the screen. Each of them has its own drawing object. Everything is drawn perfectly. EXCLUDES text. It works fine in Gingerbread, but ICS + has no text.

Here is my drawing method:

protected void onDraw(Canvas canvas) { canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.scale(getWidth(), getHeight()); drawGrid(canvas); drawHeader(canvas); drawSelected(canvas); drawDays(canvas); drawToday(canvas); canvas.restore(); } 

Grid, Selected and Today are working fine. Title and Days are text and they do not work.

Here is the drawHeader method:

 private void drawHeader(Canvas canvas) { canvas.drawText("Sun", DAYS[0], .05f, paintDaysOfTheWeek); canvas.drawText("Mon", DAYS[1], .05f, paintDaysOfTheWeek); canvas.drawText("Tues", DAYS[2], .05f, paintDaysOfTheWeek); canvas.drawText("Wed", DAYS[3], .05f, paintDaysOfTheWeek); canvas.drawText("Thurs", DAYS[4], .05f, paintDaysOfTheWeek); canvas.drawText("Fri", DAYS[5], .05f, paintDaysOfTheWeek); canvas.drawText("Sat", DAYS[6], .05f, paintDaysOfTheWeek); canvas.drawLine(.01f, .0f, .99f, .0f, paintMediumBlack); canvas.drawLine(.01f, .07f, .99f, .07f, paintMediumBlack); } 

Any ideas?

+4
source share
2 answers

I fixed the problem by adding

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) setLayerType(LAYER_TYPE_SOFTWARE, paint) 

to your user view. Not sure why I need it, and if anyone can explain it, it will be great.

+3
source

When hardware acceleration is turned on, it sometimes makes optmizations, removing drawing calls that, in its opinion, are not needed.

For example, if you have a View under a different view, it may decide not to display it if it is hidden, so there is no need to display it.

+1
source

All Articles