安卓通知大图样式和大文本样式

9
我使用Big Picture Style构建了一个推送通知,如此处所示here。是否有可能像附图中所示混合使用Big Picture Style和Big Text Style?如何实现?

请检查这个解决方案,它会帮助你 https://dev59.com/04vda4cB1Zd3GeqPUQ-h#44757879 - Ravindra Kushwaha
3个回答

18
你应该可以这样做:

您应该能够以这种方式完成:

Notification notif = new Notification.Builder(context)
     .setContentTitle("Title")
     .setContentText("content")
     .setSmallIcon(R.drawable.ic_small)
     .setLargeIcon(bitmap)
     .setStyle(new Notification.BigPictureStyle()
         .bigPicture(bigBitmap)
         .setBigContentTitle("big title"))
     .build();

来源


8
有没有同时实现多行和大画面风格的方法? - bitsabhi
不使用预定义的样式,但可以通过自定义通知和远程视图实现。 - Simon Marquis

4

在您的通知中查看更多...文本是子文本。 因此,在使用bigpicturestyle通知时,您需要设置

bigPicStyle.setSummaryText(mContent);

或者

mBuilder.setSubText(mSubText);

同时设置两个参数是不起作用的。

1

创建 BigPictureStyle 通知的示例:

 int NOTIFICATION_ID = 1;
    String ns = Context.NOTIFICATION_SERVICE;

    //Get the bitmap to show in notification bar
    Bitmap bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    Bitmap big_bitmap_image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);


    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle()
            .bigPicture(big_bitmap_image)
            .setSummaryText(getResources().getString(R.string.content));

    NotificationCompat.Builder nb = new NotificationCompat.Builder(this);

            nb.setContentTitle("Notification title"))
            .setContentText("Notification Content")
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(bitmap_image)
            .setTicker("Notification ticker!")
            //API Level min 16 is required
            .setStyle(style)
            .build();


    Intent notificationIntent = new Intent(this, MainActivity2.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    TaskStackBuilder TSB = TaskStackBuilder.create(this);
    TSB.addParentStack(MainActivity.class);

    TSB.addNextIntent(notificationIntent);
    PendingIntent resultPendingIntent = TSB.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    nb.setContentIntent(resultPendingIntent);
    nb.setAutoCancel(true);
    NotificationManager mNotificationManager =
            (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(NOTIFICATION_ID, nb.build());

这是完整的代码:

https://github.com/Jorgesys/Android-Notifications


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接