[英]How to change local notification icon?
I made the local notification icon with png file.我用png文件制作了本地通知图标。 However, in android, the icon looks transparent.但是在android中,图标看起来是透明的。 It looks good in ios app.它在 ios 应用程序中看起来不错。 How can I show the original icon image as a notification icon?如何将原始图标图像显示为通知图标?
ios notification icon ios 通知图标
android notification icon android 通知图标
Notification code通知代码
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
// import 'package:timezone/data/latest_all.dart' as tz;
// import 'package:timezone/timezone.dart' as tz;
final notifications = FlutterLocalNotificationsPlugin();
initNotification() async {
var androidSetting = const AndroidInitializationSettings('ic_launcher');
var iosSetting = const IOSInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
);
var initializationSettings = InitializationSettings(
android: androidSetting,
iOS: iosSetting
);
await notifications.initialize(
initializationSettings,
);
}
showNotification() async {
var androidDetails = const AndroidNotificationDetails(
'ID',
'notification',
priority: Priority.high,
importance: Importance.max,
// color: Color.fromARGB(255, 255, 0, 0),
);
var iosDetails = const IOSNotificationDetails(
presentAlert: true,
presentBadge: true,
presentSound: true,
);
notifications.show(
1,
'title1',
'content1',
NotificationDetails(android: androidDetails, iOS: iosDetails)
);
}
I have the same problem today.我今天也有同样的问题。 For android, you need to change the icon, android -> app -> main -> res -> drawable and that name put inside对于android,您需要更改图标, android -> app -> main -> res -> drawable 并将该名称放在里面
var androidSetting = const AndroidInitializationSettings('ic_launcher');
inside but for iOS I don't know where to change里面但是对于iOS我不知道在哪里改变
You can try this for android icon你可以试试这个 android 图标
https://medium.com/nonstopio/change-the-firebase-notification-icon-in-a-flutter-245b7f7dc546 https://medium.com/nonstopio/change-the-firebase-notification-icon-in-a-flutter-245b7f7dc546
Yes, you can use png image color, and it will show color icon on notification.是的,您可以使用 png 图像颜色,它会在通知上显示颜色图标。
ex: image file ic_launcher.png例如:图像文件 ic_launcher.png
create new file in your drawable folder在您的可绘制文件夹中创建新文件
launcher_notification.xml launcher_notification.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:gravity="fill" android:src="@drawable/ic_launcher"/>
</item>
<item>
<bitmap android:gravity="center" android:src="@drawable/ic_launcher"/>
</item>
</layer-list>
and put "launcher_notification" in并将“launcher_notification”放入
var androidSetting = const AndroidInitializationSettings('launcher_notification');
if it show grey icon on emulator, try it on your phone.如果它在模拟器上显示灰色图标,请在您的手机上尝试。 It's same if you want to use it for firebase notification icon如果您想将其用于 firebase 通知图标,则相同
If it helps, I just change the icon in the @mipmap
files and keep the same name as ic_launcher
.如果有帮助,我只需更改@mipmap
文件中的图标并保持与ic_launcher
相同的名称。 The code does the rest.代码完成剩下的工作。 It's a lazy approach but prevents you from an big headache这是一种懒惰的方法,但可以防止你头疼
If your notification Icon is displaying a grey or white color, check if the image you are using is transparent.如果您的通知图标显示灰色或白色,请检查您使用的图像是否透明。
android/app/src/main/res/drawable
.将图像放在android/app/src/main/res/drawable
中。 Ex: notification.png
例如: notification.png
const androidSetting = AndroidInitializationSettings('notification');
where notification
is the name of the image you put inside the drawable
directory without the extension .png
.其中notification
是您放入drawable
目录中的图像的名称,没有扩展名.png
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.