Android 7.0通知图标显示为白色正方形 [英] android 7.0 Notification icon appearing white square
问题描述
我正在使用以下代码段在我的android应用中生成通知.
I am using the below snippet to generate notifications in my android app.
private void sendNotification(String contentText, String message) {
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.putExtra("clear","clear");
resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent piResult = PendingIntent.getActivity(this, 0, resultIntent,0);
NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setColor(ContextCompat.getColor(getApplicationContext(),R.color.red))
.setContentTitle("title")
.setContentText(message)
.setAutoCancel(true)
.setLargeIcon(BitmapFactory.decodeResource(getResources()
,R.drawable.notification))
.setContentIntent(piResult);
NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);
int i;
for(i=0; i<messageList.size();i++){
notification.addLine(messageList.get(i));
}
notification.setBigContentTitle("title");
notification.setSummaryText(contentText);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID,notification.build());
}
它可在android 5和6中工作,但对于android牛轧糖则无法工作
It works in android 5 and 6 but for android nougat it is not working
推荐答案
遵循 docs :
状态栏图标仅由透明背景上的白色像素组成,并在适当的情况下使用alpha混合以实现平滑的边缘和内部纹理.
Status bar icons are composed simply of white pixels on a transparent backdrop, with alpha blending used for smooth edges and internal texture where appropriate.
您的整个图像,但是透明部分将被转换为白色(原来是白色或有颜色).
Your whole image but the transparent parts is going to be converted to white (being originally white or having colors).
一种解决方案是创建带有颜色的轮廓图标,通过这种方式,您可以在所有Android API中使用相同的图像.一个示例可能是该图标:
One solution is to create a silhouette icon with color, by this way you can use the same image in all Android APIs. One example could be this icon:
在较低版本的Android中,您会看到黑色的面孔,在最新版本中,您会看到相同的面孔,但带有白色.那是因为透明的部分(似乎消除了透明性,您可以从
In lower versions of Android you would see the black face, in the last versions you will see the same face but with white color. That's because of the transparent parts (it seems SO removes the transparency, you can get the original from here) of the image.
这篇关于Android 7.0通知图标显示为白色正方形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!