Best code examples for Android Toast class (android.widget.Toast)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Toast class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android Toast examples from Open Source projects
Examples using Android Toast setDuration method:
This code example shows how to use the following methods: setDuration, setGravity, setView, show
103:	final Toast myToast = new Toast(mActivity); 
-
106:	myToast.setView(myView); 
107:	myToast.setDuration(Toast.LENGTH_SHORT); 
108:	myToast.setGravity(Gravity.BOTTOM | Gravity.CENTER, 0, 0); 
109:	myToast.show(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setDuration, setGravity, setView, show
94:	Toast toast = new Toast( mContext.getApplicationContext() ); 
-
96:	toast.setGravity( gravity, 0, 0 ); 
97:	toast.setDuration( duration ); 
98:	toast.setView( layout ); 
99:	toast.show(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setDuration, setView, show
27:	Toast toast = new Toast(this); 
28:	toast.setDuration(Toast.LENGTH_LONG); 
29:	toast.setView(toastLayout); 
30:	toast.show(); 
Full Snippet Info
9
CodeRank
Examples using Android Toast makeText method:
This code example shows how to use the following methods: finish, startActivity, setClass, makeText
61:	Toast.makeText(context,message,Toast.LENGTH_LONG).show(); 
-
63:	Intent i = new Intent().setClass(context, TabWidget.class); 
64:	context.startActivity(i); 
-
66:	context.finish(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getResources, makeText
90:	final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; 
-
92:	* context.getResources().getDisplayMetrics().density); 
-
94:	Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: runOnUiThread, getString, makeText
83:	showToast( activity, activity.getString( resId, formatArgs ) ); 
-
104:	sToast = Toast.makeText( activity, message, Toast.LENGTH_SHORT ); 
-
124:	activity.runOnUiThread( sToastMessager ); 
Full Snippet Info
7
CodeRank
Examples using Android Toast getXOffset method:
This code example shows how to use the following methods: getXOffset, getYOffset, setGravity, show
113:	mToast.setGravity(Gravity.CENTER, mToast.getXOffset() / 2, mToast.getYOffset() / 2); 
114:	mToast.show(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getXOffset, getYOffset, setGravity, show
114:	mToast.setGravity(Gravity.CENTER, mToast.getXOffset() / 2, mToast.getYOffset() / 2); 
115:	mToast.show(); 
Full Snippet Info
6
CodeRank
Examples using Android Toast setText method:
This code example shows how to use the following methods: setText, show
308:	mToast.setText(context.getString(message)); 
309:	mToast.show(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setText, show
43:	toast.setText(sText); 
44:	toast.show(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setText, show
99:	lastText.setText(text); 
-
101:	lastText.show(); 
Full Snippet Info
5
CodeRank
Examples using Android Toast setGravity method:
This code example shows how to use the following methods: setDuration, setGravity, setView, show
88:	mToast.setView(mView); 
89:	mToast.setDuration(Toast.LENGTH_SHORT); 
90:	mToast.setGravity(Gravity.TOP, 0, 0); 
91:	mToast.show(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setDuration, setGravity, setView, show
88:	mToast.setView(mView); 
89:	mToast.setDuration(Toast.LENGTH_SHORT); 
90:	mToast.setGravity(Gravity.TOP, 0, 0); 
91:	mToast.show(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setDuration, setGravity, show
52:	mToast.setGravity(Gravity.CENTER, 0, 0); 
53:	mToast.setDuration(length); 
54:	mToast.show(); 
Full Snippet Info
6
CodeRank
Examples using Android Toast cancel method:
This code example shows how to use the following methods: cancel
31:	sToast.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel
31:	sToast.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel, getView
112:	if ((tooltip != null) && (tooltip.getView().getParent() != null)) { 
113:	tooltip.cancel(); 
Full Snippet Info
6
CodeRank
Examples using Android Toast show method:
This code example shows how to use the following methods: show
86:	mToast.show(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: show
40:	toast.show(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: show
61:	mToasts.put(id, t = Toast.makeText(this, id.intValue(), Toast.LENGTH_SHORT)); 
62:	t.show(); 
Full Snippet Info
6
CodeRank
Examples using Android Toast setView method:
This code example shows how to use the following methods: setDuration, setView, show
18:	Toast toast = new Toast(context); 
-
22:	toast.setView(toastLayout); 
23:	toast.setDuration(length); 
24:	toast.show(); 
Full Snippet Info
6
CodeRank
Examples for other Android Toast methods:
Related Android Toast Questions & Answers:
Toast Class Overview
A toast is a view containing a quick little message for the user. The toast class helps you create and show those.

When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved. The easiest way to use this class is to call one of the static methods that constructs everything you need and returns a new Toast object. Developer Guides For information about creating Toast notif...
Methods
  • cancel
    Close the view if it's showing, or don't show it if it isn't showing yet.
  • getXOffset
    Return the X offset in pixels to apply to the gravity's location.
  • getYOffset
    Return the Y offset in pixels to apply to the gravity's location.
  • makeText
    Make a standard toast that just contains a text view with the text from a resource.
  • setGravity
    Set the location at which the notification should appear on the screen.
  • setText
    Update the text in a Toast that was previously created using one of the makeText() methods.
  • show
    Show the view for the specified duration.