我一直在尝试使用Glide库在自定义通知中显示.gif图像。但是我只能在通知面板上显示静态图像。
RemoteViews collapsedView = new RemoteViews(getPackageName(), R.layout.notification_collapsed);
RemoteViews expandedView = new RemoteViews(getPackageName(), R.layout.notification_expanded);
collapsedView.setTextViewText(R.id.text_view_collapsed_1,"Hello World!");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(collapsedView)
.setCustomBigContentView(expandedView);
final Notification notification = mBuilder.build();
notificationManager.notify(NOTIFICATION_ID,notification);
notificationTarget = new NotificationTarget(
getApplicationContext(),
R.id.image_view_expanded,
expandedView,
notification,
NOTIFICATION_ID
);
Glide.with(MainActivity.this)
.asBitmap()
.load(R.drawable.giphy)
.into(notificationTarget);
可绘制对象是一个 .gif 文件。当通知弹出时,它显示一个静态图像,因为我使用了 .asBitmap()。我尝试过使用
Glide.with(MainActivity.this)
.asGif()
.load(R.drawable.giphy)
.into(notificationTarget);
但我遇到了一个错误:“无法解析方法'into(NotificationTarget)'”。 我已经寻找了解决方案,但是没有找到。那么我该如何在Android的通知面板中使用Glide显示GIF文件呢?是否有可能实现?