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...

Tabs in Android


You need to use a TabHost and a TabWidget. The TabHost must be the root node for the layout, which contains both the TabWidget for displaying the tabs and a FrameLayout for displaying the tab content.TabHost allows the user to create tabs.


main.xml:



    <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bckground"
android:orientation="vertical"
android:padding="5dp" >

<TabWidget
   android:id="@android:id/tabs"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:tabStripEnabled="false" />

<FrameLayout
   android:id="@android:id/tabcontent"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" />

              </LinearLayout>

         </TabHost>

TabBarActivity.java


import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
 
public class TabBarActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
        TabHost.TabSpec spec;
        Intent intent;
 
        intent = new Intent().setClass(this, FirstActivity.class);
        spec = tabHost.newTabSpec("First").setIndicator("First")
                      .setContent(intent);
        tabHost.addTab(spec);
 
        intent = new Intent().setClass(this, SecondActivity.class);
        spec = tabHost.newTabSpec("Second").setIndicator("Second")
                      .setContent(intent);
        tabHost.addTab(spec);
 
      }
      }

tab_test.xml:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<TextView
   android:id="@+id/txtDisplayedTab"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:text="TextView"
   android:gravity="center|center_vertical">
</TextView>
 
     </RelativeLayout>

FirstActivity.java




 
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
 
public class FirstActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_test);
 
        TextView txtView = (TextView) findViewById(R.id.txtDisplayedTab);
        txtView.setText("First Tab is Selected");
    }
    }

SecondActivity.java


 
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
 
public class SecondActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_test);
 
        TextView txtView = (TextView) findViewById(R.id.txtDisplayedTab);
        txtView.setText("Second Tab is Selected");
    }



Comments

Popular posts from this blog

Webview data directory for Android 9 (Pie)

DatePicker in Android