Android通知未在棉花糖中显示颜色图标 [英] Android Notification is not showing Colour Icon in Marshmallow

查看:118
本文介绍了Android通知未在棉花糖中显示颜色图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作应用程序,即我要从Parse获取数据并将该数据传输到Notification以生成并显示给用户.

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

在所有其他Android版本中,它的工作都很好,但是在棉花糖中,我选择的它的白色令人毛骨悚然的图标并不实际.

In every other Android Version its working totally fine, but in Marshmallow its creepy white icon not actual which i select.

这是我的通知代码.

 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.

推荐答案

首先:并非来自棉花糖,通知图标开始从棒棒糖本身变成WHITE.

First : Its not from Marshmallow, Notification icon started turning out WHITE from Lollipop itself.

结帐 http://developer.android.com/design/style/iconography.html 您会看到白色样式是通知在Android Lollipop中的显示方式.

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.

在Android Lollipop中,Google还建议您使用一种颜色,该颜色将显示在(白色)通知图标的后面-

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

第二个:解决方案是将LargeIcon设置为Notification Builder

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 :

您还可以使用.setColor()将颜色设置为通知图标"的背景.

You can also set the color to background of Notification Icon by using .setColor().

这篇关于Android通知未在棉花糖中显示颜色图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆