Android 通知未在 Marshmallow 中显示颜色图标 [英] Android Notification is not showing Colour Icon in Marshmallow
问题描述
我正在制作应用程序是我从Parse
获取数据并将该数据传输到通知以生成并向用户显示.
但由于某些原因,我无法在棉花糖中显示正确的彩色图标
在所有其他 Android 版本中,它的工作完全正常,但在 Marshmallow 中,它令人毛骨悚然的白色图标不是我选择的实际图标.
这是我的通知代码.
Intent cIntent = new Intent(context, MainActivity.class);PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,cIntent, PendingIntent.FLAG_UPDATE_CURRENT);NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_launcher).setContentText(数据).setContentTitle("来自解析的通知").setContentIntent(pendingIntent);通知通知 = builder.build();NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);nm.notify(100, 通知);
请帮我解决这个问题,或者告诉我如何解决这个问题.
第一:它不是来自 Marshmallow,通知图标开始从 Lollipop 本身变成白色.
结帐
您也可以使用.setColor()
设置通知图标背景的颜色.
I am Making application is which i am getting data fromParse
and transfering that data to Notification to generate and show it to user.
But for Some Reason I am unable to show correct Coloured Icon in Marshmallow
In every other Android Version its working totally fine, but in Marshmallow its creepy white icon not actual which i select.
Here is my Code of Notification.
Intent cIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
cIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentText(data)
.setContentTitle("Notification from Parse")
.setContentIntent(pendingIntent);
Notification notification = builder.build();
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100, notification);
Please Help me with this, or tell me any other way how to get rid of this problem.
First : Its not from Marshmallow, Notification icon started turning out WHITE from Lollipop itself.
Checkout http://developer.android.com/design/style/iconography.html you will see that the white style is how notifications are meant to be displayed in Android Lollipop.
In Android Lollipop, Google also suggests you to use a color that will be displayed behind the (white) notification icon - https://developer.android.com/about/versions/android-5.0-changes.html
Second : Solution to this is setting LargeIcon
to Notification Builder
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(largeIcon)
.setContentText(data)
.setContentTitle("Notification from Parse")
.setContentIntent(pendingIntent);
then, your Notification will look something like this :
You can also set the color to background of Notification Icon by using .setColor()
.
这篇关于Android 通知未在 Marshmallow 中显示颜色图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!