How to create Custom Notification in android

后端 未结 4 1198
庸人自扰
庸人自扰 2021-02-10 04:51

I need to create a custom notification instead of the default notification in android. Current notification have a icon,heading and message like below image

4条回答
  •  醉酒成梦
    2021-02-10 05:18

    That's called Expanded layouts which is available right from Jelly Bean version.

    There are 2 views of Notifications:

    1. Normal View
    2. Big View

    A notification’s big view appears only when the notification is expanded, which happens when the notification is at the top of the notification drawer, or when the user expands the notification with a gesture. Expanded notifications were first introduced in Android 4.1 JellyBean [API 16].

    In your case, you just want to display big picture in notification, give Notification.BigPictureStyle a try:

    Bitmap remote_picture = null;
    
    // Create the style object with BigPictureStyle subclass.
    NotificationCompat.BigPictureStyle notiStyle = new 
            NotificationCompat.BigPictureStyle();
    notiStyle.setBigContentTitle("Big Picture Expanded");
    notiStyle.setSummaryText("Nice big picture.");
    
    try {
            remote_picture = BitmapFactory.decodeStream(
                    (InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
            e.printStackTrace();
    }
    
    // Add the big picture to the style.
    notiStyle.bigPicture(remote_picture);
    

提交回复
热议问题