picture of my notification
I'm trying to create a full-width custom notification for my Flutter app on Android.
The problem is that the notification always appears centered with large horizontal margins, even though my layout uses match_parent for the width.
I'm calling native Kotlin through a MethodChannel, and everything displays, but the notification never spans the full width.
Custom Layout (custom_notification.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/notification_background_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/notification_color">
<!-- other views (ImageView, TextViews, etc.) -->
</LinearLayout>
Kotlin Notification Helper (NotificationHelper.kt)
package com.example.pomodo
import android.app.NotificationManager
import android.content.Context
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import com.example.pomodo.R
class NotificationHelper(private val context: Context) {
private val CHANNEL_ID = "custom_notification_channel"
fun showCustomNotification(title: String, body: String, backgroundColor: Int) {
val customNotificationLayout = RemoteViews(context.packageName, R.layout.custom_notification).apply {
setTextViewText(R.id.notification_title, title)
setTextViewText(R.id.notification_body, body)
}
val builder = NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setStyle(NotificationCompat.DecoratedCustomViewStyle()) // suspected issue
.setCustomContentView(customNotificationLayout)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(1001, builder.build())
}
}
Sagar Zala
5,18210 gold badges38 silver badges67 bronze badges
New contributor
Supra Bob is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
-
please add pictures of your ui problem you are refering to.Mohammad Ali Ghasemian– Mohammad Ali Ghasemian2025年11月15日 20:31:13 +00:00Commented 2 days ago
-
@MohammadAliGhasemian hello thanks for the reply. ithink the picture is at the top of this post as "example"Supra Bob– Supra Bob2025年11月15日 20:39:04 +00:00Commented 2 days ago
-
I don't think that's controllable. None of the applications have that.NirajDota– NirajDota2025年11月16日 13:51:21 +00:00Commented yesterday
default