【问题标题】:Notification text is too long and is not showing full text通知文本太长且未显示全文
【发布时间】:2020-04-21 19:43:08
【问题描述】:

我正在为 android 2.3.3 开发一个应用程序。我正在显示一个通知,但该通知的文本太长,并且它没有显示全文并且它被剪切了,所以我怎样才能在我的通知中显示我的全文?

代码如下:

String message = "Tonights Taraweeh consists of Alif Lam Mim and the first quarter of Sayaqul. The Surahs covered are Al-Fatiha(The Opening),and the first two-thirds of Al-Baqara(The Cow).";
Notification notification = new Notification();
notification.setLatestEventInfo(context, title, message, contentIntent);

【问题讨论】:

  • 请出示一些代码。
  • 您必须提供您的代码,我们才能为您提供帮助
  • 是的,请显示您的相关代码部分。你是通过 Toast 展示的吗?如果是,则在 Toasts 上显示长文本不是一个好习惯,因为如果用户在任何地方触摸屏幕,Toasts 可能会被用户完成。这可能会在用户无意的情况下发生。 AlertDialog 是更好的解决方案
  • +1 @CRUSADER 指出了一个解决方案。不幸的是,这表明人们搜索他们的答案的方式很糟糕,因为这些问题已经得到了回答。

标签: android notifications


【解决方案1】:

扩展通知仅适用于 Android 4.1,read here

Android 2.3.3 使用旧的通知,没有扩展。如果您在 Android 4.1 或更早版本中显示通知,则必须使用较短的文本、剪切文本(并在用户单击时显示全文)或调整文本。

【讨论】:

    【解决方案2】:

    你必须设置BigTextStyle

    Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
                .setSmallIcon(R.drawable.new_mail)
                .setContentTitle(emailObject.getSenderName())
                .setContentText(emailObject.getSubject())
                .setLargeIcon(emailObject.getSenderAvatar())
                .setStyle(new NotificationCompat.BigTextStyle()
                        .bigText(__BigTextHere___))
                .build();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-07
      相关资源
      最近更新 更多