用较长的文字Android的多行通知/通知通知、较长、文字、Android

2023-09-13 00:14:05 作者:南巷挽清風

我需要创建一个通知一个较长的文本,这可能吗?默认情况下它是不会,但你可以使用自定义布局,这是我做的。现在我可以显示多行,但你可以看到,文本仍然是断开的/没有完全显示出来? ):是否有人可以告诉我,我在做什么错/如果有一个固定的限制通知的大小?如果你看一下截图,你会发现,仍有很大的空间留给...感谢您的任何提示!

I need to create a Notification with a longer text, is that possible? By default it is not, but you can use a custom layout, which is what I did. Now I can display multiple lines, but as you can see, the text is still broken / not displayed completely? ): Can someone please tell me what I am doing wrong / if there's a fixed limit for the size of notifications? If you look at the screenshot you will notice, that there is still a lot of space left... Thanks for any hint!

顺便说一下这里的用于自定义布局的XML基础上的http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomNotification

BTW here's the XML used for the custom layout, based on http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomNotification

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="3dp"
          >
<ImageView android:id="@+id/image"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_marginRight="10dp"
          />
<TextView android:id="@+id/text"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:textColor="#000"
          />
</LinearLayout>

推荐答案

有关果冻豆及以上,你可以使用一个可扩展的通知。最简单的方法是使用NotificationCompat.BigTextStyle为您的通知。

For Jelly Bean and higher you can use an expandable notification. The easiest way is to use the NotificationCompat.BigTextStyle for your notification.

像这样:

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(getString(R.string.title));
bigTextStyle.bigText(getString(R.string.long_explanation));

mBuilder.setStyle(bigTextStyle);