如何为进度通知图标设置动画 [英] How to animate the progress notification icon

查看:88
本文介绍了如何为进度通知图标设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过以下方式构建服务"中的通知进度栏:

I am building the notification progress bar in Service in such a way that is given below :

private NotificationManager mNotifyManager;
private NotificationCompat.Builder mBuilder;



 mBuilder =
                    new NotificationCompat.Builder(DownloadService.this)
                            .setSmallIcon(R.drawable.download)
                            .setContentTitle("MayUp")
                            .setContentText("Downloading new tools")
                            .setTicker("Downloading in progress");
            mBuilder.setAutoCancel(true);
            Intent targetIntent = new Intent(DownloadService.this, ListClass.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(DownloadService.this);
            // Adds the back stack for the Intent (but not the Intent itself)
            stackBuilder.addParentStack(MyActivity.class);
            // Adds the Intent that starts the Activity to the top of the stack
            stackBuilder.addNextIntent(targetIntent);
//            PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//            mBuilder.setContentIntent(contentIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);

            mNotifyManager.notify(1, mBuilder.build());

            mBuilder.setProgress(100, 0, false);
            mNotifyManager.notify(1, mBuilder.build());

它的工作正常,通知和进度条都显示良好,我想要通知中的简单进度条,它很简单,对此我没有问题,但是下面给出了我想要的:

its working fine , the notification and the progress bar is showing all fine , I wanted the simple progress bar in the notification and it is the simple and I have no problem with that but what I want is given below :

我想要的东西:

我希望我的通知图标可以像Google Play一样进行动画处理 商店应用的功能,它会对其图标进行动画处理,以显示该下载位置 进步.我也想这样做.请告诉我使用生成器和 通知管理器我如何得到这个,我已经看过很多教程 但已弃用.

I want that My notification Icon should animate like the google play store app does, it animates its icon to show that download in progress. I want to do the same. Please tell me by using builder and notification manager How can I get this , I have seen many tutorial but they are deprecated.

推荐答案

您可以按照Rushab patel的答案制作动画列表,如上所述,但是如果您使用最新的api,并且定位目标是新SDK.

you can make the animation list as described above in the answer of Rushab patel but there could be problem if you are using the newst api and if you are targetting the new sdk .

因此此行将过时或过时

Notification notification = new Notification(R.drawable.wheelAnim, null,System.currentTimeMillis());

Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis());

在编写通知时太糟糕了,如上所述,我必须建议您使用通知构建器,因此,我建议您直接在通知构建器中使用此可绘制动画列表.

which is too bad in coding notification , I must suggest you as you have described above that you are using notification builder , thus I would recomend you to directly use this animation list drawable in the notification builder.

摘录中的

mBuilder =
                    new NotificationCompat.Builder(DownloadService.this)
                            .setSmallIcon(R.drawable.youAnimationList)
                            .setContentTitle("MayUp")
                            .setContentText("Downloading new tools")
                            .setTicker("Downloading in progress");
            mBuilder.setAutoCancel(true);

这篇关于如何为进度通知图标设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆