棒棒糖通知图标太小

时间:2015-05-10 12:19:27

标签: android notifications icons android-5.0-lollipop

我正在尝试此代码,

NotificationCompat.Builder nfBuilder = new NotificationCompat.Builder(
            context)
            ..setContentTitle(
                    "XYZ")
            .setContentText("ABC")![enter image description here][1]
            .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);

问题是,它适用于所有其他平台,但是使用棒棒糖,它会显示非常小的图标,周围有灰色圆圈。我尝试更改图标大小并使用setLargeIcon()方法,但仍然没有快乐。

enter image description here

2 个答案:

答案 0 :(得分:4)

图像应该是正方形比例。 使用此工具(https://romannurik.github.io/AndroidAssetStudio/icons-notification.html),然后确保使用“Api v11”图标,因为它们具有您需要的方形比例,旧版本的高度稍高。

回顾: 我得告诉我,我真的没有看到你的图标太小,事实上这是我能得到的最大图标尺寸,看起来......

The size is the same as yours

对于“灰色”背景问题,Notification.Builder.setColor(Color.RED)不适合你吗?

答案 1 :(得分:1)

这是最终解决的问题:

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. 获取drawable / mipmap。
  2. 将其转换为位图。
  3. 使用setLargeIcon(Bitmap bitmap)的{​​{1}}方法设置位图。
  4. 注意: NotificationCompat.Builder这是一种修改方法。你不能跳过它。