wverdese
wverdese

Reputation: 159

Android's Expanded Notifications - Both Standard ContentView and custom BigContentView after expansion

I've made a custom RemoteView in JellyBean, as described here, and set it as the bigContentView of a notification.

notification.bigContentView = customNotifView;

I'm trying to have the custom layout placed below the standard contentView after the expansion; something like this.

The problem is that the custom layout overrides the standard contentView after the expansion.

Is there a way to do that?

Upvotes: 2

Views: 6030

Answers (3)

Jan Maděra
Jan Maděra

Reputation: 546

Much simple solution would look like this

        RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.big_notificaiton_layout);
        fillTextViews(profile, contentView);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannelHelper.Channel.Channel.getId())
                .setContentIntent(intent)
                .setContentTitle(context.getResources().getString(R.string.profile_name_is_active, profile.getTitle()))
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setCustomBigContentView(contentView)
                .setOngoing(true)
                .setSmallIcon(R.drawable.icon);

You have to set NotificationCompat.DecoratedCustomViewStyle().

Upvotes: 2

wverdese
wverdese

Reputation: 159

I solved by creating a custom layout for the contentView called layout_base_content_notification.xml, which is exactly the same (handmade) layout Android provides for notifications.

RemoteViews collapsedViews = new RemoteViews(c.getPackageName(), R.layout.layout_base_content_notification);
Notification noti = builder.build();
noti.contentView = collapsedViews;

Then I've included it in a customLayout, called layout_big_content_notification.xml:

<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/layout_base_content_notification" />

And added it as a bigContentView:

RemoteViews expandedViews = new RemoteViews(c.getPackageName(), R.layout.layout_big_content_notification);
noti.bigContentView = expandedViews;

Now, after the expansion, the bigContentView replaces the contentView, but their header is the same.

Please let me know if there is a better solution.

Upvotes: 5

Harshit Rathi
Harshit Rathi

Reputation: 1862

You need to create your own RemoteViews, then indicate that you want the expanded content to inherit your custom RemoteViews.

RemoteViews expandedView = new RemoteViews(YOUR CONTEXT.getPackageName(), YOUR CUSTOM LAYOUT);
 Notification notification = mBuilder.build();
 notification.bigContentView = expandedView;

or check this link.

Upvotes: 0

Related Questions