我有一个通知,其中包含少量文本,但它仍然太大,无法显示在通知栏中,因此它被缩写了。我发现它是发出自定义通知的唯一解决方案,但对于我想做的事情来说似乎有点矫枉过正。
我可以使通知滚动文本或扩展通知文本区域,以便它显示全文而不仅仅是其中的前几个单词吗?
我目前通过以下方式调用通知:
private void triggerNotification() {
Notification notification = new Notification(R.drawable.ic_launcher,
"Title", System.currentTimeMillis());
notification.setLatestEventInfo(this, "First text",
"This is the text that gets abberviated with .. when it is too long",
PendingIntent.getActivity(this, 0, new Intent(this,MainActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
PendingIntent.FLAG_CANCEL_CURRENT));
notification.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(0, notification);
}
最佳答案
在 API 16+ 中,有一个 Notification.Builder允许您添加 subtext 的类它可以是多行(如 Gmail notifications )。我不知道 the support library 中是否包含 Notification.Builder
但我想可能是这样。你可以检查一下。
但是,如果它不在支持库中并且您必须坚持使用您的 minSdkVersion,那么除了实现您自己的通知版本之外,恐怕没有办法做您想做的事情。
更新:
支持库的最新版本(2012 年 8 月发布的版本 10)引入了 Android 4.1 通知样式:BigTextStyle 。有一个很好的例子告诉你如何使用它。检查一下here .
关于android - 通知中的滚动文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11939018/