具有较长文本的Android多行通知/通知

ste*_*wpf 21 notifications android

我需要创建一个包含更长文本的通知,这可能吗?默认情况下不是,但您可以使用自定义布局,这就是我所做的.现在我可以显示多行,但正如您所看到的,文本仍然被破坏/未完全显示?):有人可以告诉我我做错了什么/如果通知的大小有固定的限制吗?如果你看一下屏幕截图,你会注意到,还剩下很多空间......感谢任何提示!

BTW这里是用于自定义布局的XML,基于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>
Run Code Online (Sandbox Code Playgroud)

更长的通知文本

Cis*_*elo 48

对于Jelly Bean及更高版本,您可以使用可扩展通知.最简单的方法是使用NotificationCompat.BigTextStyle进行通知.

像这样:

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

mBuilder.setStyle(bigTextStyle);
Run Code Online (Sandbox Code Playgroud)


小智 41

NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_notification)
                    .setContentTitle(title)
                    .setStyle(new NotificationCompat.BigTextStyle()
                                      .bigText(message))
                    .setContentText(message)                                            
                    .setDefaults(NotificationCompat.DEFAULT_SOUND)
                    .setContentIntent(contentIntent)
                    .setAutoCancel(true);

mNotificationManager.notify(requestID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)

曾经有人试过https://developer.android.com/guide/topics/ui/notifiers/notifications.html


ina*_*ruk 5

通知视图受到65sp高度的限制.这是实现细节,没有记录,并且已在Android 4.1中进行了更改以支持可扩展通知.所以不要依赖这个特定的值,而是依赖于视图的高度有限的事实.

这是status_bar_latest_event.xml用于在通知区域中膨胀视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="65sp"
    android:orientation="vertical"
    >

    <com.android.server.status.LatestItemView android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="64sp"
            android:background="@drawable/status_bar_item_background"
            android:focusable="true"
            android:clickable="true"
            android:paddingRight="6sp"
            >
    </com.android.server.status.LatestItemView>

    <View
        android:layout_width="match_parent"
        android:layout_height="1sp"
        android:background="@drawable/divider_horizontal_bright"
        />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)


And*_*dre 1

我的理解是,Android 的通知系统对每个通知的高度都有限制,以避免单个通知填满屏幕。

从您链接的页面:

注意:当您使用自定义通知布局时,请特别注意确保您的自定义布局适用于不同的设备方向和分辨率。虽然此建议适用于所有视图布局,但对于通知尤其重要,因为通知抽屉中的空间非常有限。不要使您的自定义布局过于复杂,并确保在各种配置中对其进行测试。

但是,您可以显示多个通知、“粘性”通知或通知内的滚动文本。

有关可以使用通知执行哪些操作的更多信息,请参阅:

通知通知生成器