[英]android notification icon showing as white block
I have been having trouble with a icon showing with my notification.我的通知显示图标有问题。 I have gone trough the material designs page for icons and Notification doc .
我已经浏览了图标和通知文档的材料设计页面。
I used different scales, in BMP 256 color format: 360px, 144px, 48px, 24px 16px all continued showing a white block.我使用了不同的比例,在 BMP 256 颜色格式中:360px、144px、48px、24px 16px 都继续显示白色块。
I changed format to PNG, used 144px (named "ic_notify_icon", used in code), still no luck.我将格式更改为 PNG,使用 144px(名为“ic_notify_icon”,在代码中使用),仍然没有运气。
//Global
private NotificationManager mNotifyManager ;
private Notification mNotify;
private void initialize() {
mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder mNotificationBuilder = new Notification.Builder(this);
mNotificationBuilder.setSmallIcon(R.mipmap.ic_notify_icon);
mNotificationBuilder.setContentTitle("A Title here");
mNotificationBuilder.setContentText("Some content text here");
mNotify = mNotificationBuilder.build();
ShowNotify();
}
private void ShowNotify(){
//...some code here
mNotifyMan.notify(0, mNotify);
//...some code here
}
Any suggestions?有什么建议吗?
ps I had a look at this post , also same question but I do not find it helpful/useful, or I just do not understand the requirements... ps我看过这篇文章,也是同样的问题,但我觉得它没有帮助/有用,或者我只是不明白要求......
I have found the solution!我找到了解决办法!
I only found hints on what the requirements are for a Android Notification (SDK 22 / Version 5.1.1)but after searching for over 4 hours, finally a complete and working solution for this.我只找到了有关 Android 通知(SDK 22/版本 5.1.1)要求的提示,但在搜索了 4 多个小时后,终于找到了一个完整且有效的解决方案。
Here are the steps I followed and it seems to be inline with what is mentioned on various forums, questions/answers and doc, but no "steps/requirements" of what is needed:以下是我遵循的步骤,它似乎与各种论坛、问题/答案和文档中提到的内容一致,但没有所需的“步骤/要求”:
Creating and preparing your image创建和准备您的图像
click File > Save As or press 's'
click File > Save As or press 's'
You should have a Save Dialog
open (and a save options dialog, top right - if not, right at the bottom of the save dialog, select the Save options dialog
checkbox, and it should open)你应该有一个
Save Dialog
打开(和一个保存选项对话框,右上角 - 如果没有,在保存对话框的底部,选择Save options dialog
复选框,它应该打开)
My settings (which were given by default) are:我的设置(默认设置)是:
Check the following 2 boxes:选中以下 2 个框:
In Android Studio:在 Android Studio 中:
Right-Click Drawable folder > Add image asset
(any resource folder should do) Right-Click Drawable folder > Add image asset
(任何资源文件夹都应该这样做) Notification Icon
from the top drop-down list (default is Launcher Icon
)Notification Icon
(默认为Launcher Icon
) Image > Browse to image> click ok
Image > Browse to image> click ok
this is normal since the Lollipop SDK (API 21 - Ver 5.0.1)
only allows this type of color scheme, in searching I came across the materials design page which mentioned something in this line (Someone can extend on why this is)这是正常的,因为
Lollipop SDK (API 21 - Ver 5.0.1)
只允许这种类型的配色方案,在搜索时我遇到了材料设计页面,其中提到了这一行中的内容(有人可以扩展为什么会这样)
Below, you will notice your notification icon in different 'dpi resolutions', adding a image normally will show a white block, but adding transparency solves this.在下面,您会注意到您的通知图标具有不同的“dpi 分辨率”,添加图像通常会显示一个白色块,但添加透明度可以解决这个问题。
I believe one can use this from a 'colorful' perspective, in this case, IrfanView has a default background of black, this creating a "inverted" image in respect to this color (assuming in IrfanView , one leaves the "Use main windows color for transparency - checked" ) you can create different and interesting images.我相信人们可以从“多彩”的角度使用它,在这种情况下, IrfanView的默认背景为黑色,这会创建一个与此颜色相关的“倒置”图像(假设在IrfanView 中,留下“使用主窗口颜色”透明度 - 选中”),您可以创建不同且有趣的图像。
I really hope this helps!我真的希望这会有所帮助!
The notification icon in android must be transparent and have no background color! android中的通知图标必须是透明的,没有背景色!
If the icon have a rounded color background, the icon will become a white rounded block.如果图标具有圆形背景色,则图标将变为白色圆形块。
Only an icon with a very transparent background can be used as a notification icon.只有背景非常透明的图标才能用作通知图标。
I have had this problem before, the problem is the size of the image you're using, try to resize it to 32x32 png.我以前遇到过这个问题,问题是您使用的图像的大小,尝试将其调整为 32x32 png。
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_tend_notification)
.setContentTitle(Constants.APP_NAME)
.setContentText(message)
.setTicker(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.