I want to add text on bitmap and set it in ImageView on App-Widget, here is my code:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.img);
Canvas canvas = new Canvas(bitmap.copy(Bitmap.Config.ARGB_8888, true));
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
paint.setTextSize(20);
paint.setTextAlign(Paint.Align.CENTER);
paint.setAntiAlias(true);
//int xPos = (canvas.getWidth() / 2);
//int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
int xPos = (canvas.getWidth() / 2);
int yPos = (canvas.getHeight() / 2);
canvas.drawText("My Text", xPos, yPos, paint);
views.setImageViewBitmap(R.id.widgetImg, bitmap);
appWidgetManager.updateAppWidget(appWidgetId, views);
But in AppWidget it's just simple image (R.drawable.img
) and there is no text over it.
Any one knows the problem?