I have gone through the following tutorials
https://developer.android.com/training/notify-user/expanded.html
https://developer.android.com/training/notify-user/build-notification.html
I want to show notifications with multiple line as shown in the layout below.
But I am not able to see the multiline text as shown in the image below. The first line is the title, while the second line is the body.
Here is my code to build the notification builder.
// Helper function to create NotificationChannels and a builder for the channel id.
final NotificationCompat.Builder builder = makeNotificationBuilder();
if (builder == null)
return null;
final RemoteViews collapsedView = new RemoteViews(context, R.layout.notification_template);
builder.setContent(contentView);
// Trying to set the text
NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
builder.setStyle(style);
if (notification.getTitle() != null)
builder.setContentTitle(notification.getTitle());
style.setBigContentTitle(notification.getTitle());
if (notification.getBody() != null)
builder.setContentText(notification.getBody());
style.bigText(notification.getBody());
. . . . . Code to set the intent.. It works
if (expandedView != null)
builder.setCustomBigContentView(expandedView);
builder.setAutoCancel(true);
return builder.build();
Layout file
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="false"
android:background="@drawable/notification_material_bg">
<TextView
android:id="@+id/notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:fadingEdge="horizontal"
android:singleLine="false"
android:maxLines="2"
android:textAppearance="@style/NotificationTitle"
tools:ignore="Deprecated"
/>
<TextView
android:id="@+id/notification_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:layout_weight="1"
android:ellipsize="end"
android:fadingEdge="horizontal"
android:textAppearance="@style/NotificationText"
tools:ignore="Deprecated"
/>
</LinearLayout>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.