Android:如何在通知的范围内调整NotificationCompat.Builder的largeIcon

时间:2015-06-11 11:29:52

标签: android notifications android-notifications

我已经建立了一个通知,但是当我设置大图标时,它不适合边界。我会将其设置为按预期显示。

以下是创建通知的代码:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
    .setSmallIcon(R.drawable.ic_launcher)
    .setLargeIcon(image)
    .setContentTitle(appName)
    .setContentText(message)
    .setSound(defaultSoundUri)
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setContentIntent(pendingIntent);

1 个答案:

答案 0 :(得分:0)

尝试使用自定义布局显示通知:

这可能会对您有所帮助:

NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);

        RemoteViews contentView = new RemoteViews(pkgName, R.layout.custom_notification);
        contentView.setImageViewResource(R.id.notification_image, appIcon);
        contentView.setTextViewText(R.id.notification_text, message);
        notification.contentView = contentView;