Sunday 13 September 2015

Custom Toast Alert :-)



In this example creating a custom toast alert.
android.widget.Toast class used to create toast alert message.
Toast alert is a notification message that display for certain amount of time, and automatically fades out after set time. 

Use
To show alert message to user.
To debugging your application.
To show alert from background service,broadcast,receiver,getting data from server...etc.






To access toast_border.xml - Click here Toast_Border
To access toast_border.xml - Click here Toast
 Function to call the customeToast from activity class- Calltoast();


public void Calltoast(){
Context context = getApplicationContext();
        // Create layout inflator object to inflate toast.xml file
        LayoutInflater inflater = getLayoutInflater();           
        // Call toast.xml file for toast layout 
        View toastRoot = inflater.inflate(R.layout.toast, null);       
        Toast toast = new Toast(context);      
        // Set layout to toast 
        toast.setView(toastRoot);
        toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL,
                0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.show();
}







No comments:

Post a Comment

How to do text writing animation?  In Android Development we do not have the option to use any other custom font in our default Tex...