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());
}
4

2 回答 2

10

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

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

神奇的事情发生了,你的图标是动画的。它与此错误有关:

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

希望它可以帮助某人。

于 2013-03-09T13:22:35.910 回答
2

只是为了添加到@gingo 的答案,如果您不希望在状态栏中显示任何文本,则将您的 notification_ticker 字符串在 strings.xml 中保持为空白(这很明显)。

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

 mBuilder.setSmallIcon(R.drawable.ic_download);
 mNotifyManager.notify(0, mBuilder.build());
于 2014-02-18T10:32:26.653 回答