【偶遇BUG】android通知栏的smallicon不生效
【现象】
NotificationManager manager = (NotificationManager) XXXXXXService.this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder( XXXXXXService.this); builder.setContentTitle("XXXX"); builder.setContentText("YYYYY"); builder.setAutoCancel(true); builder.setSmallIcon(R.drawable.ic_launcher);//就是这句话 Notification notification = builder.build(); notification.when = System.currentTimeMillis(); Intent intent = new Intent(getApplicationContext(), YYYYYYYYYActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(XXXXXXXXXXXX, XXXXXX); PendingIntent pendIntent = PendingIntent.getActivity(getApplicationContext(), subtitle.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.contentIntent = pendIntent; manager.notify(subtitle.hashCode(), notification);
如上代码呈现一个通知栏,但展开通知栏时R.drawable.ic_launcher在GoogleNexus6(android5.1)上是个圆圈加方框的图,收起通知栏的时候更像是个铜钱的形状. 不去自定义RemoteView的情况下,有方案说把那个图片资源背景搞成透明的,但这样的话收起通知栏时那个图片资源不是彩色的.
【分析】
猜想大概是android为了配合新的主题样式,把smallicon改造成了黑白的了.(如果你知道具体原因请留言)
【修正】
将targetSdkVersion改为20