Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a single line android notification (only title)

I want to set a notification for my app in the notifications drawer, but only with a title in it (no body), meaning - only one line of notification, which should be vertically aligned to the app icon.

For example, in the following notification I'd like to keep only the "Ringer shushed 'til 19:16" title, in the same font size, but vertically centered to the app icon on the left.

enter image description here

Here is my code for creating the notification:

NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, MainActivity.class), PendingIntent.FLAG_CANCEL_CURRENT);

PendingIntent deleteIntent = PendingIntent.getService(context, 0,
                new Intent(context, GCMIntentService.class)
                        .setAction(IntentConsts.ACTION_CLEAR_MESSAGE_COUNT), PendingIntent.FLAG_CANCEL_CURRENT);

manager.notify(MMConfig.NTF_ID_GCM, new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.push_icon)
                .setContentTitle("My title")
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(true)
                .setContentIntent(contentIntent)
                .setDeleteIntent(deleteIntent)
                .build());

Right now I succeed creating the notification with only title in it, but I can't seem to make it vertically centered with the app icon. Any ideas?

like image 744
limlim Avatar asked Nov 23 '22 00:11

limlim


1 Answers

Like some suggested, I used RemoteViews to customize my notification, as following:

final RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification_new_message);

views.setTextViewText(R.id.title, title);

Notification notification = new Notification();
notification.contentView = views;
notification.icon = R.drawable.push_icon;
notification.contentIntent = contentIntent;

manager.notify(Config.NTF_ID_GCM, notification);

Where I set inside my notification_new_message.xml the desirable look of my notification.

like image 142
limlim Avatar answered Nov 25 '22 14:11

limlim