我正在尝试制作自定义通知,但最终总是很小(大约大多数通知的大小)。我可以看到 Netflix 和 Youtube 在投射到 chromecast 设备时显示更大的通知,这些通知看起来是自定义的(它们可能是大视图)。他们是如何使它们变得如此之大?
谢谢。
编辑:将其标记为已回答,因为评论指出bigContentView
你似乎已经知道了...您可能在谈论大视图样式通知。谷歌有具体的培训文档以及技术指南。下面是那里的一些示例代码:
// Constructs the Builder object.
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_notification)
.setContentTitle(getString(R.string.notification))
.setContentText(getString(R.string.ping))
.setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
/*
* Sets the big view "big text" style and supplies the
* text (the user's reminder message) that will be displayed
* in the detail area of the expanded notification.
* These calls are ignored by the support library for
* pre-4.1 devices.
*/
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.addAction (R.drawable.ic_stat_dismiss,
getString(R.string.dismiss), piDismiss)
.addAction (R.drawable.ic_stat_snooze,
getString(R.string.snooze), piSnooze);
请注意对setStyle
的调用。