SoFunction
Updated on 2025-03-11

Android programming method to implement flashing effect in the notification bar above

This article describes the method of Android programming to implement the flashing effect in the notification bar above. Share it for your reference, as follows:

Show notification code:

private void showNotification(Context ctx, String url) {
    Notification n = new Notification();
     |= Notification.FLAG_SHOW_LIGHTS;
     |= Notification.FLAG_AUTO_CANCEL;
     = Notification.DEFAULT_SOUND;
     = .ic_launcher;
     = ();
    Intent intent = new Intent(Intent.ACTION_VIEW);
    (Intent.FLAG_ACTIVITY_NEW_TASK);
    ((), ());
    PendingIntent pi = (ctx, 0, intent, 0);
    (ctx, "title", "summary", pi);
    NotificationManager manager = (NotificationManager) (Context.NOTIFICATION_SERVICE);
    (0, n);
}

If you want to set the image flash, there is no API. You can only set the image with animation effect. Replace the above code. Google's download notification is considered an animation, and its implementation is:

<animation-list
  xmlns:andro
    android:oneshot="false">
  <item android:drawable="@drawable/stat_sys_download_anim0" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim1" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim2" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim3" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim4" android:duration="200" />
  <item android:drawable="@drawable/stat_sys_download_anim5" android:duration="200" />
</animation-list>

For more information about Android related content, please check out the topic of this site:Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Android multimedia operation skills summary (audio, video, recording, etc.)》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.