I want to show this kind of message in Android top after finishing some background work. How do I show this kind of notification ? Thanks..
-
Use custom toast, refer this http://stackoverflow.com/questions/11288475/custom-toast-in-android-a-simple-example – Remees M Syde Oct 28 '14 at 10:42
-
What stops you using a TextView aligned to the Parent's top, with a left compound drawable inside? Normally it would be INVISIBLE and then you make it visible only when required. – Phantômaxx Oct 28 '14 at 10:47
4 Answers
That looks like the ticker text of a Notification
, assuming that this screenshot is of the top of the screen. You can add that to the Notification
via setTicker()
on your NotificationCompat.Builder
. Note, though, that ticker text is no longer displayed as of API Level 21 (Android 5.0). Also note that ticker text automatically disappears after a couple of seconds.

- 986,068
- 189
- 2,389
- 2,491
This is a Notification alert, this can be started from services, activities,fragments, broadcaster receivers,etc... Check this link: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
This example was copied from google dev:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ResultActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build());
Good luck!

- 761
- 5
- 13
Build a notification and use setTicker (Look at the doc there) :
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_event)
.setContentTitle(eventTitle)
.setContentText(eventLocation)
.setContentIntent(viewPendingIntent)
.setTicker("Your message");

- 12,208
- 9
- 44
- 47
You can use SYSTEM_ALERT_WINDOW which will show message always on Top whether your application is foreground or background.
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER|Gravity.TOP;
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.addView(view, params);
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

- 28,348
- 10
- 61
- 77