Reputation: 10586
This is very specific to number of line of notification displays to user by default
This is how other apps and are showing two line of notification
While my notification is only one liner
how can i make notification two liner
This is my code.
Intent intent = new Intent(RegisterActivity.this, RegisterActivity.class);
intent.putExtra(NotificationUtility.NOTIFICATION_TYPE, getString(R.string.notification_type_register));
intent.putExtra(MainActivityList.LAUNCH_ACTIVITY, MainActivityList.LAUNCH_MAIN_LIST);
PendingIntent contentIntent = PendingIntent.getActivity(RegisterActivity.this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(NotificationCompat.PRIORITY_MAX);
if(title != null){
bigTextStyle.setBigContentTitle(title);
builder.setContentTitle(title);
}
if (display_message != null){
bigTextStyle.bigText(display_message);
builder.setContentText(display_message);
}
bigTextStyle.setSummaryText(summaryText);
builder.setStyle(bigTextStyle);
builder.setAutoCancel(true);
builder.setDefaults(Notification.DEFAULT_ALL);
builder.setContentIntent(contentIntent);
builder.setDeleteIntent(cancelIntent);
Notification notification = builder.build();
// Add as notification
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(notificationId, notification);
Upvotes: 0
Views: 143
Reputation: 983
You can use the following code, it works for me
RemoteViews myView = new RemoteViews(context.getPackageName(),
R.layout.notifybaralert);
myView.setTextViewText(R.id.tv_NotifyAlertTitle, msgTitle);
myView.setTextViewText(R.id.tv_NotifyAlertMsg, msgBody);
notify.setSmallIcon(R.drawable.ic_launcher); //to set icon that appers on the bar
notify.setAutoCancel(true);
notify.setContentIntent(pintent);
notify.setContent(myView);
notify.setContentTitle(msgTitle); //to set title that appears on the bar
Here myView
is RemoteView type.
The xml for notifybaralert is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_NotifyAlertTitle"
style="@style/NotificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Babaji Shivram"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/tv_NotifyAlertMsg"
style="@style/NotificationText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="8"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
It gives the notification exactly like the image that you provided.
Hope this helps :)
Upvotes: 1