
Я пытаюсь создать настраиваемое уведомление во всю ширину для моего приложения Flutter на Android.
Проблема в том, что уведомление всегда отображается по центру с большими горизонтальными полями, хотя мой макет использует match_parent для ширины.
Я вызываю собственный Kotlin через MethodChannel, и все отображается, но уведомление никогда не охватывает всю ширину.
Пользовательский макет (custom_notification.xml)
Помощник по уведомлениям Kotlin (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())
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... full-width
Мобильная версия