【发布时间】:2014-05-10 12:40:33
【问题描述】:
我想在通知抽屉中为我的应用设置一个通知,但其中只有一个标题(没有正文),这意味着 - 只有一行通知,应该与应用图标垂直对齐。
例如,在以下通知中,我只想保留“Ringer shushed 'til 19:16”标题,字体大小相同,但垂直居中于左侧的应用图标。
这是我创建通知的代码:
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());
现在我成功地创建了只有标题的通知,但我似乎无法让它与应用程序图标垂直居中。有什么想法吗?
【问题讨论】:
-
你见过其他实现这一目标的应用吗?
-
你的意思是垂直居中吗? Google Now 似乎有单行通知,但它们没有居中。
-
@weston 不,但这似乎是一件经典的事情,我没有看到任何关于它的文档。
-
@RichardLeMesurier 是的,垂直居中。
-
在这里查看答案stackoverflow.com/a/16168704/383414,了解如何进行自定义布局。
标签: android vertical-alignment android-notifications