Implement expand and collapse notification android

后端 未结 5 1180
余生分开走
余生分开走 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:21

    An expandable Notification is a special case of a Notification Big View. If the Big View is not at the top of the notification drawer, it it shown 'closed' and is expandable by swipe. Quote from Android Developers:

    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 are available starting with Android 4.1.

    The Big View Notification can be created as follows:

    Notification notification = new Notification.BigTextStyle(builder)
    .bigText(myText).build();
    

    or

    Notification notification = new Notification.BigPictureStyle(builder)
    .bigPicture(
      BitmapFactory.decodeResource(getResources(),
        R.drawable.my_picture)).build();
    

    Here is a tutorial.

提交回复
热议问题