Android-显示动画状态栏图标
我正在尝试将我的通知状态栏图标设置为动画android.R.drawable.stat_sys_upload,它工作正常,但图标不会动画:Android-显示动画状态栏图标,android,android-notifications,Android,Android Notifications,我正在尝试将我的通知状态栏图标设置为动画android.R.drawable.stat_sys_upload,它工作正常,但图标不会动画: private void showStatusNotification() { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Builder notificati
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());
}
解决方案很简单,但非常棘手。你只需要添加
notificationBuilder.setTicker(getString(R.string.notification_ticker));
魔法发生了,你的图标也被激活了。它与此错误有关:
希望它对某人有所帮助。只需添加到@gingo的答案中,如果您不想在状态栏中显示任何文本,请在strings.xml中将您的通知代码字符串保留为空(这是很明显的) 此外,如果您希望动画图标在进度或下载/上载完成后停止,请将外观类似的图标设置为notificationBuilder,并在notification manager上调用notify方法,如下所示:
mBuilder.setSmallIcon(R.drawable.ic_download);
mNotifyManager.notify(0, mBuilder.build());