簡體   English   中英

Android:如何在通知范圍內調整NotificationCompat.Builder的largeIcon

[英]Android: How to adjust the largeIcon of a NotificationCompat.Builder in the bounds of the notification

我已經建立了一個通知,但是當我設置大圖標時,它不適合邊界。 我將其設置為按預期顯示。

這是創建通知的代碼:

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);

嘗試使用自定義布局顯示Notification:

這可以幫助您:

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM