安卓 - 显示动画状态栏图标

7

我正在尝试将我的通知状态栏图标设置为动画android.R.drawable.stat_sys_upload,它可以正常工作,但是图标不会动画:

private void showStatusNotification() {

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setAutoCancel(false);
    notificationBuilder.setOngoing(true);
    notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this,
            MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
    notificationBuilder.setContentTitle(getString(R.string.notification_title));
    notificationBuilder.setContentText(getString(R.string.notification_text));
    notificationBuilder.setSmallIcon(android.R.drawable.stat_sys_upload);
    notificationManager
            .notify(STATUS_NOTIFICATION_ID, notificationBuilder.build());
}
2个回答

10
这个解决方案很简单,但是非常棘手。你只需要添加

notificationBuilder.setTicker(getString(R.string.notification_ticker));

神奇的事情发生了,您的图标被动画化了。这与这个bug相关:

http://code.google.com/p/android/issues/detail?id=15657

希望对某些人有所帮助。


2

补充@gingo的答案,如果您不希望在状态栏中显示任何文本,则将strings.xml中的notification_ticker字符串保留为空(这是相当明显的)。

此外,如果您希望动画图标在进度或下载/上传完成后停止,则将类似外观的图标设置为notificationBuilder,并在通知管理器上调用notify方法,如下所示:

 mBuilder.setSmallIcon(R.drawable.ic_download);
 mNotifyManager.notify(0, mBuilder.build());

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接