如何在 android 棒棒糖版本上设置通知图标

How to set notification icon on android lollipop version

我正在使用此代码进行通知。它适用于所有版本,但在棒棒糖中它显示白色图标代替我的通知图标。

  private void sendNotification(String msg) {
    //Notification notifyObj = null;
    mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MenuActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.appicon)
    .setContentTitle("New Notification")// Vibration
    .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
    .setLights(Color.RED, 3000, 3000)
    .setWhen(System.currentTimeMillis())
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(msg))
    .setContentText(msg);
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

设置小图标前需要检查SDK版本

而不是 .setSmallIcon(R.drawable.appicon) 采用 .setSmallIcon(CallNotiIcon())

在 CallNotiIcon 方法中,使用这个

private int CallNotiIcon() {
boolean Icon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
return Icon ? R.drawable.appicon : R.drawable.<NEW ICON FOR LOLIPOP>;
}

确保检查 http://developer.android.com/design/style/iconography.html