I am trying to set a custom notification layout
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.image_customNote,R.mipmap.ic_notification);
contentView.setTextViewText(R.id.title_customNote,title);
contentView.setTextViewText(R.id.text_customNote, messageBody);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setPriority(Notification.PRIORITY_HIGH)
.setAutoCancel(true)
//.setContentText(title)
// .setContentText(messageBody)
.setTicker(title)
.setSound(defaultSoundUri)
/* .setStyle(new NotificationCompat.BigTextStyle().bigText(title))
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))*/
.setCustomContentView(contentView)
.setCustomBigContentView(contentView)
.setContentIntent(pendingIntent)
.setSmallIcon(getNotificationIcon()).setColor(ContextCompat.getColor(this, R.color.colorPrimary));
// .addAction(R.drawable.ic_launcher, "Previous", pendingIntent)
// .setColor(ContextCompat.getColor(this, R.color.colorPrimary));
notificationManager.notify(new Random().nextInt(), notificationBuilder.build());
this is the code i am trying ,
Here is my xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_customNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />
<TextView
android:id="@+id/title_customNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:layout_toRightOf="@id/image_customNote"
/>
<TextView
android:id="@+id/text_customNote"
android:textColor="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title_customNote"
android:layout_toRightOf="@id/image_customNote" />
</RelativeLayout>
When i recieve a notification the custom view does not get set and the notification view is completely blank ... please help
The problem is in your xml.
This xml worked for me :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_customNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />
<TextView
android:id="@+id/title_customNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_blue_dark"
android:layout_toRightOf="@id/image_customNote" />
<TextView
android:id="@+id/text_customNote"
android:textColor="@android:color/holo_blue_dark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title_customNote"
android:layout_toRightOf="@id/image_customNote" />
</RelativeLayout>

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With