Create a Custom Notification with Custom Message in Android

How to Create a Custom Notification in Android. Let’s create an android example to genereate a custom notification with a custom message in Android.

Android SDK that we are going to use here is the set of development tools to develop applications for the android platform. With the help of this, we are going to create a notification with a custom message with a vector image.

Create a Custom Notification with Custom Message in Android

Anroid project structure:

Step 1: Create a project with Empty Activity.

  • Button object will be used to connect with the button view.
  • EditText object will be used to connect with the edit view.
  • Button and EditText is a view in our main screen when the user interacts with a button or edit text we can perform certain actions with the help of an object.
  • To connect the object to view we use the findViewById method and pass the id of view, we can assign every view a unique id and connect them to different objects.
  • setOnClickListener method will execute when the user clicks on the button view.
  • getText.toString method will return text written in the editText view.
  • NotificationCompat class is used to build notification with, which is used to display app content in a floating window.
  • Builder is used to build the notification.
  • setSmallIcon method will display a small icon before the notification message.
  • setContentTitle method will Set the title of the notification.
  • setContentText method will set the custom message which we entered in the edit text view.
  • setAutoCancel method will dismiss the notification when the user clicks on the notification.
  • NotificationManager class is used to notify the user of events happing.
  • .notify method will execute our custom notification 0 is id and is our notification.
package com.example.notificationapp;


import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
private Button button;
private EditText editText;
   protected void onCreate(Bundle savedInstanceState) {
       button = findViewById(;
       editText = findViewById(;
       button.setOnClickListener(new View.OnClickListener() {
           public void onClick(View view) {
               String msg =editText.getText().toString();
               NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this)
                       .setContentTitle("New Notification")
               NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


  • RelativeLayout is our view Group to display child views at a certain position
  • Layout_width tag is used to set the width of the view. match parent will change the size of view to the size of its parent here to the size of the screen
  • Layout_height tag will set the height of the layout to the size of the screen
  • Warp_content will set the size to size of data hold into view
  • EditText is our text view in which we can enter text,
  • Id tag is used to give the view a unique id which can be used to assign object to view.
  • layout_centerInParent tag will align the view at the center of the screen
  • marginBottom will give spacing below the view.
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""

       android:hint="Custom Notification"
       android:ems="10" />


Step 2: Create vector Icon

  • Goto res directory -> drawable right-click on drawable new -> Vector Asset

  • Click on clip art and save it as ic_baseline_notifications_24.xml

In this way, we learned how to create a notification with a custom message in Android.

Android practice tasks