Android - 如何在通知中显示大文本

标签 android notifications

我需要实现一段代码,用于在通知中显示包含 200 个字符的大文本。在这里我使用了以下代码,但它显示单行。

       Intent notificationIntent;
       NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.icon)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(message)
                .setDefaults(Notification.DEFAULT_ALL)
                .setAutoCancel(true);
        notificationIntent = new Intent(context, Main.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pintent = PendingIntent.getActivity(context, 0,
                notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(pintent);
        NotificationManager mNotifyMgr = 
                (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        // Builds the notification and issues it.
        mNotifyMgr.notify(1, mBuilder.build());

最佳答案

您可以选择不同的样式用于通知生成器:

在你的情况下,我会使用NotificationCompat.BigTextStyle。更多详情可查看here.

使用时不要忘记导入 v4 支持。

关于Android - 如何在通知中显示大文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23799669/

相关文章:

Android Things - 当我不知道 IP 地址时如何连接到我的树莓派

android - SnackBar 落后于其他 View

android - 一次通知Compat

iOS 通知推送与电池电量

Android 推送通知 : Get data, 在点击通知时存储并显示在新 Activity 上

android - 使用安卓布局

Android UI 设计 : Supporting Multiple Screens

android - Imageview 在 android 中单击和双击?

android - 模拟器中通知中的声音问题

ios - 在应用程序终止时安排本地通知