Showing posts with label Toast Message. Show all posts
Showing posts with label Toast Message. Show all posts

Tuesday, November 29, 2016

Toast Message


In Android, Toast is a notification message that pop up for certain amount of time, and 
automtaically fades out, most people just use it for display sort message. 
 
 Toast.makeText(this, "Message...", Toast.LENGTH_SHORT).show();

Steps to use toast message in your project.
  1. Crate a project in android studio. 
  2. There are two type of toast message used in android. which are-
    1. Simple Toast
    2. Custom Toast

      Both are described in this demo.
       
  3.  Update your main_activity.xml
    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        tools:context="com.pankaj.toastdemo.MainActivity">
       
        <!--__________________________________________________-->
        <!--                                                                                                    -->
        <!--                   create two buttons with onclick event                       -->
        <!--__________________________________________________-->
       
     <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/activity_vertical_margin"
            android:onClick="showSimpleToastMessage"
            android:text="Show Simple Toast Message" />
       
     <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="showCustomToastMessage"
            android:text="Show Custom Toast Message" />
    
    </LinearLayout>
    
    
      
  4. Create "custom_toast_view.xml" and update to-
    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#abcdef"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:padding="@dimen/activity_vertical_margin">
    
        <!--_________________________________________________-->
        <!--                                                                                                  -->
        <!--                        Add an image and a text view                           -->
        <!--_________________________________________________-->
      
      <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher" />
      
      <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_vertical_margin"
            android:text="click on Shos Simple Toast Message" />
    
    </LinearLayout>
    
    
      
  5. Update your MainActivity.JAVA

    package com.pankaj.toastdemo;
    
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
      
        /*____________________________________________________________*/
        /*                                                                                                                       */
        /*__Methode will be call when user click on "Show Simple Toast Message"__*/
        /*____________________________________________________________*/
       
     public void showSimpleToastMessage(View view) {
            Toast.makeText(this, "click on \"Show Simple Toast Message\".", Toast.LENGTH_SHORT).show();
        }
       
    
        /*____________________________________________________________*/
        /*                                                                                                                        */
        /*__Methode will be call when user click on "Show Custom Toast Message"__*/
        /*____________________________________________________________*/
       
    
     public void showCustomToastMessage(View view) {
            
    //create the LayoutInflater object
            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
          
      //Create custom view object
            View customToastView=inflater.inflate(R.layout.custom_toast_view,null);
          
      //create toast object
            Toast toast=new Toast(this);
          
      //update toast to custom view
            toast.setView(customToastView);
       
         //show toast
            toast.show();
        }
    }
      

  6. Now all the development for toast message has completed, Please run the application.

     

  7. Now click on "SHOW SIMPLE TOAST MESSAGE" and see the result on screen-

  8. Now click on "SHOW CUSTOM TOAST MESSAGE" and see the result on screen-



  9.  Good bye, Thanks to read this blog.




Wednesday, November 23, 2016

Basic Android


Android Version History & Main Features - It took only five years from the release of the first device running Android for the platform to become the most popular mobile operating system on the planet.


Hello World - It will be a simple program in which we will see how to output a sample text, say, Hello World.


Toast Message - In Android, Toast is a notification message that pop up for certain amount of time, and automtaically fades out, most people just use it for display sort message.


TextView - InAndroid,  TextView is use to display text data on the screen. For thebetter user interference this is very important to customize the textview. In this tutorial i am covering some points of customization. 


Radio Group/RadioButton - In Android, Radio Group/Radio Button is use to select single option from number of choice. For the better user interference this is very important to customize the radio button according to need of theme. In this tutorial i am covering some points of customization.


Spinner - Spinner is use to select single option from number of listed choice.


Rating Bar - Rating Bar is use to get/indicate rating . 


TimePicker - Time Piker is a type of dialog in android which is used to get time by the user.

DatePicker - Date Piker is a type of dialog in android which is used to get date by the user. 


Progress Bar - Progress Bar is a element used to visualize the progression of an extended running operation, such as a download, file transfer, or installation. Sometimes, the graphic is accompanied by a textual representation of the progress in a percent format.


Menu - Context Menu, Option Menu, Popup Menu, Main MenuMenu is use to select single option from number of listed choice.

Intent, Explicit Intent - When a intent is created with directly define target component then it is called Explicit Intent.