Implement expand and collapse notification android

后端 未结 5 1087
余生分开走
余生分开走 2021-02-01 15:44

I need to implement expand and collapse notification in status bar for android 4.0 and above version. I have search on google for this but didn\'t getting any code solution for

5条回答
  •  抹茶落季
    2021-02-01 16:43

    There is a method for this function you can show a small icon when notification collapsed and show a large one when a notification expanded.

    val bitmap = BitmapFactory.decodeResource(resources, R.drawable.notification)
    
    var notification = NotificationCompat.Builder(context, CHANNEL_ID)
        .setSmallIcon(R.drawable.new_post)
        .setContentTitle(imageTitle)
        .setContentText(imageDescription)
        .setLargeIcon(bitmap)
        .setStyle(NotificationCompat.BigPictureStyle()
                .bigPicture(bitmap)
                .bigLargeIcon(null))
        .build()
    

提交回复
热议问题