0

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
asked 2 days ago
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.
3
  • please add pictures of your ui problem you are refering to. Commented 2 days ago
  • @MohammadAliGhasemian hello thanks for the reply. ithink the picture is at the top of this post as "example" Commented 2 days ago
  • I don't think that's controllable. None of the applications have that. Commented yesterday

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.