Simple Notification in Android

Image
Notifications are a way to provide information to your customer which displays as a pop up on the device. It helps you to keep in touch with your customer. I am going to create a simple notification without going deep because everything is available on Google. We must understand a few concepts before going further. Notification channel:  Assume you have developed an app for an online learning center where they teach Maths and English. Students can either learn Maths, English, or Both. we must send notification related to Maths to only students who have taken Maths. In this case, we can create channels for Maths, English, and both so triggered notification will be delivered to students who have taken that subject. Each Notification channel can have a different Notification sound and different behavior that you can change from the Notification setting page. I forgot to tell you that Google has introduced the Notification channel from Android 8.0 i.e API level 26. Now yo...

DialogBox in Android


Using DialogBox,you can display whatewer you want., the way you want it.Suppose you want you display a dialogbox onclick of a button in your main activity.

This is the layout of main activity.
main.xml

 <?xml version="1.0" encoding="utf-8"?>

   <RelativeLayout android:id="@+id/RelativeLayout01&quot;
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     xmlns:android="http://schemas.android.com/apk/res/android">

   <TextView android:id="@+id/TextView01"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
       android:text="Welcome to fafadiatech">
   </TextView>

   <Button android:layout_height="wrap_content"
    android:layout_below="@+id/TextView01"
    android:layout_width="wrap_content"
    android:id="@+id/Button01main"
    android:text="Hey! There is more...">
   </Button>

    </RelativeLayout>


Here is my dialog's layout, maindialog.xml:



   <?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="wrap_content" android:layout_height="wrap_content">

   <ImageView android:id="@+id/ImageView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_centerHorizontal="true" />

   <ScrollView android:id="@+id/ScrollView01"
    android:layout_width="wrap_content" android:layout_below="@+id/ImageView01"
    android:layout_height="200px">

   <TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
     android:layout_width="wrap_content" android:layout_height="wrap_content" />
 
   </ScrollView>

   <Button android:id="@+id/Button01" android:layout_below="@id/ScrollView01"
     android:layout_width="wrap_content" android:layout_height="wrap_content"
     android:layout_centerHorizontal="true" android:text="Cancel" />

   </RelativeLayout>



Main activity Code



    public class main extends Activity {
     @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //set up main content view
        setContentView(R.layout.main);
        //this button will show the dialog
        Button button1main = (Button) findViewById(R.id.Button01main);

         button1main.setOnClickListener(new OnClickListener() {
          @Override
             public void onClick(View v) {
                //set up dialog
                  Dialog dialog = new Dialog(main.this);
                   //set the content of dialog
                  dialog.setContentView(R.layout.maindialog);
                   //set the title of dialog
                  dialog.setTitle("FafadiaTech");
                  dialog.setCancelable(true);
                //there are a lot of settings, for dialog, check them all out!

                //set up text
                TextView text = (TextView) dialog.findViewById(R.id.TextView01);
                text.setText(R.string.lots_of_text);

                //set up image view
                ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
                img.setImageResource(R.drawable.nista_logo);

                //set up button
                Button button = (Button) dialog.findViewById(R.id.Button01);
                button.setOnClickListener(new OnClickListener() {
                @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                //now that the dialog is set up, it's time to show it  
                dialog.show();
                 }
                });
                 }
            }



Comments

Popular posts from this blog

Webview data directory for Android 9 (Pie)

Tabs in Android

DatePicker in Android