简体   繁体   English

棒棒糖通知图标太小

[英]Lollipop notification icon too small

I'm trying this code,我正在尝试这个代码,

NotificationCompat.Builder nfBuilder = new NotificationCompat.Builder(
            context)
            ..setContentTitle(
                    "XYZ")
            .setContentText("ABC")
            .setContentIntent(pIntent)
            .setDefaults(Notification.DEFAULT_ALL)
            .setOnlyAlertOnce(true)
            .setAutoCancel(true)
            .setPriority(Notification.PRIORITY_HIGH)
            .setSmallIcon(R.drawable.woj_ic_launcher);

    Notification notification = nfBuilder.build();

    NotificationManager nfManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    nfManager.notify(requestCode, notification);

Problem is, it works fine with all other platforms but with lollipop, it shows very small icon with grey circle around it.问题是,它适用于所有其他平台,但对于棒棒糖,它显示非常小的图标,周围有灰色圆圈。 I tried changing icon sizes and using setLargeIcon() method but still no joy.我尝试更改图标大小并使用 setLargeIcon() 方法,但仍然没有乐趣。

在此处输入图片说明

The image should have square proportion.图像应具有方形比例。 Use this tool ( https://romannurik.github.io/AndroidAssetStudio/icons-notification.html ) and then make sure you use the "Api v11" icons, since they have the square proportion you need, the older version had a little more height.使用这个工具( https://romannurik.github.io/AndroidAssetStudio/icons-notification.html )然后确保你使用“Api v11”图标,因为它们有你需要的平方比例,旧版本有一点更高的高度。

Recap: I got to tell I don't really see you icon being too small, in fact that's the greatest icon size I could get, look..回顾:我得说我真的没有看到你的图标太小,事实上这是我能得到的最大的图标尺寸,看..

尺寸和你的一样

And for the "grey" background issue, is something like Notification.Builder.setColor(Color.RED) not working for you?对于“灰色”背景问题,像Notification.Builder.setColor(Color.RED)这样的东西对你不起作用吗?

This is how it sorted out finally:最后是这样整理的:

NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(getApplicationContext());
nBuilder.setContentTitle("notificationTitle");
nBuilder.setSmallIcon(R.mipmap.ic_launcher);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher1);
nBuilder.setLargeIcon(bitmap);
nBuilder.setContentText(notificationText);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, nBuilder.build());
  1. Get a drawable/mipmap.获取可绘制/mipmap。
  2. Convert it to bitmap.将其转换为位图。
  3. Set the bitmap using setLargeIcon(Bitmap bitmap) method of NotificationCompat.Builder .设置使用位图setLargeIcon(Bitmap bitmap)的方法NotificationCompat.Builder

Note: setSmallIcon() is a mendatory method here.注意: setSmallIcon()在这里是一个强制方法。 You can't skip it.你不能跳过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM