B4A Library Custom Notifcations

This library is now in a usable condition and may evolve as requirements increase.

You are free to use this library in commercial/non-commericial projects. If you use it for something cool, it would be nice if you could post a screenshot of your app using this library on the forum (probably Share Your Creations).

You may use the source code and add new functions to it. If you do so, you are required to post the improvements/additions in this thread.

1. The Layout of the Notification
This is defined in an xml layout file. Create your layout, name it to "cm.xml" and copy it to your projects Objects/res/Layout folder. Mark it as read-only. See XML Resources for further information.
Make sure you give an id to each view in the xml, because in order to set these views we will use the same id.
<TextView android:id="@+id/title"
        android:layout_height="wrap_content" />
If you have trouble with the xml file (like I did), do Clean Project. Make the xml file in utf-8. warwound used dreamweaver for mine.

2. Add the Library to your project
Right hand pane, contains a library tab. Select "CustomNotifications"

3. B4A Code
Create a notification object as you normally would.
Then to customize it, do:

Dim cn as CustomNotification
Dim n As Notification 
n.Icon = "icon"

The id used here to set the properties, is the same id defined in your xml layout.

Still having problems?
Before posting a question, check and double check your xml file.
Most errors happen due to your xml file not being added as a resource. Look in the Objects/gen/<packagename>/R.java file to see it the xml file is being added into it.
Then read this link carefully and thoroughly: Custom Notifcation Layouts
Also dont try to put a listview or a scrollview in a notification. It only supports buttons, labels, progressbars, imageviews and panels. There may be other restrictions on what it supports.

XML Resources:
Learn about xml layouts and styles. Each ROM has a different style so it could cause your text to be invisible.
Custom Notifcation Layouts

Events based on individual view clicks. This requires pending intents, so far I havent been able to make it work. Please let me know if you have a solution.

There are too many people who deserve credits for this.
Erel (the platform), Barx(the enlightenment), corwin42(the functions), warwound(the xml file), NJDude(the banter), XverhelstX(the nagging), JonPM(the initial inspiration) and many others I may have forgot to mention.

Important Notice:
This library is depreciated and is left here as an archive/legacy reasons. This has been superseded by this library: Custom Notification Library: Barx


  • ExampleLayout.zip
    433 bytes · Views: 739
  • CMExample.zip
    4.9 KB · Views: 729
  • CNLibrary.zip
    4.3 KB · Views: 799
Last edited: