Guys! Who faced this? How can I implement drawing on the canvas on the widget, I apologize for the pun. The task of how to draw a line on the widget, I tried to do it in the old-fashioned way, created a view and drew it on it, but I can’t insert it into the widget, I need another way.
UPD :
I found one blog, which describes how to draw on the widget, but there is not all the code, and it is not clear where to write it. I wrote in the class successor AppWidgetProvider
, in the method onUpdate()
, but nothing has changed, there is no picture ...
UPD2:
I looked for similar questions on windowskerker and came across one and remade it for myself, it also does not work, maybe someone can fix me. Here is how I saddle:
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { RemoteViews views = new RemoteViews(context.getApplicationContext().getPackageName(), R.layout.main); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); paint.setTextSize(16); paint.setAntiAlias(true); paint.setTypeface(Typeface.MONOSPACE); Bitmap mybitmap = Bitmap.createBitmap(100, 16, Bitmap.Config.ALPHA_8); Canvas c = new Canvas(mybitmap); c.drawColor(Color.BLACK); c.drawText("fdgfdgfdgfdfdfdgGFDFGFDDDDG", 0, 0, paint); views.setImageViewBitmap(R.id.imageView1, mybitmap); }
What needs to be fixed?