Android: Custom Sliding Notification Alert

Android: Custom Sliding Notification Alert

This project is a simple demonstration of a slide in notification message I have created for android. Visually, a notification message will slide in from the top of the screen and move the rest of the content down. When the notification completes all content will slide back up to the top.

The notification can be kicked off in 2 modes:
  1. Closable Notification – This notification will show a “close icon” on the right side and stay open until the user taps the close button.
  2. Timed Notification – This notification will appear and automatically disappear after the allowed time.
Implementation

The slide in notification functionality is fairly easy to incorporate in to your own projects if you wish to. Simply include the “notification_layout.xml” layout in your own activity’s layout just like my “main_activity_layout.xml” does. Then, in your activity class, extend BaseNotificationActivity and everything will be set up for you.

Now, from your activity you can trigger the notification with the following calls:

postNotification(String message, boolean closable); This will trigger a notification message to show on the screen. By passing “true” in for closable, an icon with an “x” will be displayed that allows the user to manually cause the message to be closed. Using “false” for closable shows a message that cannot be manually closed by the user (but can be programmatically closed with hideNotification()).

postTimedNotification(String message); This will trigger a notification message to show on the screen, and it will automatically disappear after 3 seconds.

hideNotification(); Programmatically dismiss the notification message.

Compatible with gingerbread+

Source Code

https://github.com/jeffcardillo/SlideNotification

Leave a Reply