Android - 显示动画状态栏图标

时间:2013-03-09 13:19:54

标签: android android-notifications

我正在尝试将我的通知状态栏图标设置为动画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 个答案:

答案 0 :(得分:10)

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

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

魔术发生,你的图标动画。它与这个错误有关:

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

希望它有所帮助。

答案 1 :(得分:2)

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

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

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