Reputation: 647
I'm doing an home screen widget for android and I want to use a Lottie animation on the widget. I know the LottieAnimationView
is not supported as the widget only supports some views. But can I use this custom drawable LottieDrawable to use in an ImageView on the widget?
Upvotes: 1
Views: 1123
Reputation: 2853
Yes it is possible. Try something like this:
Paint p = new Paint();
p.setAntiAlias(true);
p.setStyle(Style.STROKE);
p.setStrokeWidth(8);
p.setColor(0xFFFF0000);
Bitmap bitmap = Bitmap.createBitmap(100, 100,
Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawArc(new RectF(10, 10, 90, 90), 0, 270, false, p);
RemoteViews views = new
RemoteViews(updateService.getPackageName(), R.layout.main);
views.setImageViewBitmap(R.id.canvas, bitmap);
ComponentName componentName = new
ComponentName(updateService,
DashboardAppWidgetProvider.class);
AppWidgetManager appWidgetManager =
AppWidgetManager.getInstance(updateService);
appWidgetManager.updateAppWidget(componentName,
views);
Upvotes: 0
Reputation: 1007322
No, sorry. You can only use drawable resources or bitmaps, not a Drawable
object.
While your app has Lottie, your app is not rendering the app widget. The home screen renders the app widget. Hence, the RemoteViews
system limits you to things that are part of the framework, that any home screen will be able to use.
Upvotes: 4