Notification Bar with Bigpicturestyle and 2 lines text?

Asked

Viewed 327 times

2

I need to make a notification with that aspect: inserir a descrição da imagem aqui

I’ve tried everything and I can’t find anything like it.

I managed to put 2 buttons below the image with:

            .addAction(R.drawable.sim, "Sim", pendingIntentYes)
            .addAction(R.drawable.nao, "Não", pendingIntentNo)

But really what I need and I can not at all put TWO lines or break text in setSummaryText.

Do I need to make a custom notification? If so, how can I do it this way?

Edit:

That’s exactly what I needed, someone knows how to make a notification like this. inserir a descrição da imagem aqui

1 answer

1


In order to appear the 3 lines of text plus the text "info" has to do so :

Notification notif = new NotificationCompat.Builder(this)
                .setContentTitle("Title")
                .setContentText("Text")
                .setSubText("SubText")
                .setContentInfo("info")

By setting Bigpicturestyle like this:

NotificationCompat.BigPictureStyle big = new NotificationCompat.BigPictureStyle();
big.bigPicture(bitMap)
   .setBigContentTitle("BIG TITLE")
   .setSummaryText("SUMMARY");

When the Notification is expanded:

  • the text "Title" is replaced by "BIG TITLE"
  • the text "Text" is maintained.
  • the text "Subtext" is replaced by "SUMMARY"

It is also possible to create custom Notifications using a Remoteviews passing it on to the method setContent() of Notification.Builder

Define your layout in the usual way in a xml, then build the Notification this way:

RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.customnotification);
Notification.Builder builder = new Notification.Builder(this) 
        ...
        ... 
        ... 
        .setContent(remoteViews);

Use the various methods provided by the class Remoteviews to access the views of layout.

For example remoteViews.setOnClickPendingIntent(R.id.button1, intent); assigns a pendingIntent to the button button1

  • Am I beginner as I would make this layout? Do you have any examples? How could you put buttons like the example above with this transparent background bar? Another detail as you would for the text to be in Multiple Lines?

  • The layout is done in the same way as if it were for an Activity. Multiple lines are multiple Textview

  • I edited the answer with explanation to get 3 lines of text

  • was perfect, it was exactly these 3 lines I needed. Now yes meets me perfectly, thank you very much for the solution given. Great hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.