Create Custom Big Notifications
Update due to API changes:
From API 24 on, the Notification.Builder
contains a setCustomBigContentView(RemoteViews)-method. Also the NotificationCompat.Builder (which is part of the support.v4 package) contains this method.
Please note, that the documentation for the NotificationCompat.Builder.setCustomBigContentView states:
Supply custom RemoteViews to use instead of the platform template in the expanded form. This will override the expanded layout that would otherwise be constructed by this Builder object. No-op on versions prior to JELLY_BEAN.
Therefore, this will also only work for API >= 16 (JELLY_BEAN).
Original Answer
So after excessive google usage, I found this tutorial explaining how to use custom big layouts. The trick is not to use setStyle()
but manually set the bigContentView
field of the Notification
after building it. Seems a bit hacky, but this is what I finally came up with:
notification_layout_big.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp" <!-- This is where I manually define the height -->
android:orientation="horizontal" >
<!-- some more elements.. -->
</LinearLayout>
Building Notification
in code:
Notification foregroundNote;
RemoteViews bigView = new RemoteViews(getApplicationContext().getPackageName(),
R.layout.notification_layout_big);
// bigView.setOnClickPendingIntent() etc..
Notification.Builder mNotifyBuilder = new Notification.Builder(this);
foregroundNote = mNotifyBuilder.setContentTitle("some string")
.setContentText("Slide down on note to expand")
.setSmallIcon(R.drawable.ic_stat_notify_white)
.setLargeIcon(bigIcon)
.build();
foregroundNote.bigContentView = bigView;
// now show notification..
NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyManager.notify(1, foregroundNote);
Edit
As noted by chx101, this only works for API >= 16. I did not mention it in this answer, yet it was mentioned in the given linked tutorial above:
Expanded notifications were first introduced in Android 4.1 JellyBean [API 16].
How to create a Custom Notification Layout in android?
I used BitTextStyle()
to add highlighted text in notification.
return new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_mono)
.setContentTitle(title)
.setContentText(message)
.setLargeIcon(icon)
.setColor(ContextCompat.getColor(context, R.color.notification_color))
.setStyle(new NotificationCompat.BigTextStyle().bigText(title))
.setStyle(new NotificationCompat.BigTextStyle().bigText(message).setSummaryText("#hashtag"))
.setShowWhen(true)
.setAutoCancel(true);
Create custom big notification inflate
Required notification contents
A Notification object must contain the following:
- A small icon, set by setSmallIcon()
- A title, set by setContentTitle()
- Detail text, set by setContentText()
you don't have 2 and 3.
check this
EDIT:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setCustomBigContentView(remoteViews)
.setContentTitle("My notification")
.setContentText("Hello World!");
.setAutoCancel(true);
And change your custom TextView to regular
TextView`
How to create Custom Notification in android
Notification views
Normal View - A notification in normal view appears in an area that’s up to 64 dp tall. Even if you create a notification with a big view style, it will appear in normal view until it’s expanded.
Content title
Large icon
Content text
Content info
Small icon
Notification time
Normal View Like
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]
. Expandable notifications
were designed to support rich notification style objects called Notification.Style
.
Big View Like
Go to this link expandable-notifications-android
More information on official docs
Custom Big Notification In API level 10
Big view for notifications were introduced in and android 4.1 and they're not supported on older devices. (as @Pop Tudor commented)
We can use it by
bigContentView(RemteView)
for notifications if api level is upper than 15.In API 15 or lower, we can only set custom view for notifications by
contentView(View)
method.
Related Topics
Viewpager Intercepts All X-Axis Ontouch Events. How to Disable
Illegalstateexception: Can't Change Container Id of Fragment
Mkdir() Works While Inside Internal Flash Storage, But Not Sd Card
How to Add a Switch to Android Action Bar
One Onclickhandler for Multiple Buttons
Dynamically Updating an Autocompletetextview Adapter
Travis Ci Failed Because Cannot Accept License Constrain Layout
Android Scrollview Layout Problem
Autocompletetextview Not Completing Words Inside Parentheses
How to Create Xmpp Chat Client for Facebook
Android Runtime Layout Tutorial
Android Quotes Within an SQL Query String