Toast show - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Toast show method.

This code example shows how to use the following methods:setDuration, setView, show
		TextView message = (TextView) toastLayout.findViewById(R.id.message);
		message.setText("This is my own message");
	} 
 
	public void showMessage(View view) {
		Toast toast = new Toast(this);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setView(toastLayout);
		toast.show();
	} 
} 
9
CodeRank
This code example shows how to use the following methods:setDuration, setGravity, setView, show
	 *           the gravity 
	 */ 
	public static void showCustomToast( int viewResId, int duration, int gravity ) {
		View layout = getLayoutInflater().inflate( viewResId, null );
 
		Toast toast = new Toast( mContext.getApplicationContext() );
 
		toast.setGravity( gravity, 0, 0 );
		toast.setDuration( duration );
		toast.setView( layout );
		toast.show();
	} 
	 
	static PorterDuffColorFilter mWhiteMultiplyFilter = new PorterDuffColorFilter( 0xFFFFFFFF, Mode.MULTIPLY );
 
	/** 
	 * Draw folder icon. 
	 *  
	 * @param folder 
	 *           the folder 
8
CodeRank
This code example shows how to use the following methods:setDuration, setGravity, setView, show
This code example shows how to use the following methods:getXOffset, getYOffset, setGravity, show
        } 
 
        // inform users of how long the timeout is now 
        final String toast = makeTimeoutToastString(context, screenTimeout);
        mToast = Toast.makeText(context, toast, Toast.LENGTH_LONG);
        mToast.setGravity(Gravity.CENTER, mToast.getXOffset() / 2, mToast.getYOffset() / 2);
        mToast.show();
    } 
 
    @Override 
    protected List<Uri> getObservedUris() {
        return OBSERVED_URIS;
    } 
 
    @Override 
    protected boolean handleLongClick(Context context) {
        Intent intent = new Intent("android.settings.DISPLAY_SETTINGS");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
7
CodeRank
This code example shows how to use the following methods:setText, show
     */ 
    public static void showToast(int message, Toast mToast, Context context) {
        if (mToast == null) {
            mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
        } 
        mToast.setText(context.getString(message));
        mToast.show();
    } 
 
    /** 
     * @param context 
     * @return meow 
     */ 
    public static AnimationDrawable getNyanCat(Context context) {
        final AnimationDrawable animation = new AnimationDrawable();
        for (int i = 0; i < 12; i++) {
            try { 
                animation.addFrame(Drawable.createFromStream(
                        context.getAssets().open("Frame" + i + ".png"), null), 75);
            } catch (IOException e) {
6
CodeRank
This code example shows how to use the following methods:show
                    mHandler.postDelayed(mSuperLongPress, 2*ViewConfiguration.getLongPressTimeout());
                } else if (action == MotionEvent.ACTION_UP) {
                    if (mContent.isPressed()) {
                        mContent.setPressed(false);
                        mHandler.removeCallbacks(mSuperLongPress);
                        mToast.show();
                    } 
                } 
                return true; 
            } 
        }); 
         
        setContentView(mContent);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:show
        toast.setView(layout);
        customToast.setOnClickListener(new View.OnClickListener() {
			 
			@Override 
			public void onClick(View arg0) {
		        toast.show();
		    } 
		}); 
         
    } 
} 
6
CodeRank
This code example shows how to use the following methods:setDuration, setGravity, setView, show
    protected void onBrightnessChanged(final int value, final int max) {
        mText.setText(Integer.toString(Math.round(value * 100.0f / max)) + "%");
        mText.setCompoundDrawablesWithIntrinsicBounds(mIcon, null, null, null);
	int progress = (int) (Math.round(value * 100.0f / max));
	mBrightProg.setProgress(progress);
        mToast.setView(mView);
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setGravity(Gravity.TOP, 0, 0);
        mToast.show();
    } 
 
    @Override 
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MSG_BRIGHTNESS_CHANGED: {
                onBrightnessChanged(msg.arg1, msg.arg2);
                break; 
            } 
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:setDuration, setGravity, setView, show
    protected void onBrightnessChanged(final int value, final int max) {
        mText.setText(Integer.toString(Math.round(value * 100.0f / max)) + "%");
        mText.setCompoundDrawablesWithIntrinsicBounds(mIcon, null, null, null);
	int progress = (int) (Math.round(value * 100.0f / max));
	mBrightProg.setProgress(progress);
        mToast.setView(mView);
        mToast.setDuration(Toast.LENGTH_SHORT);
        mToast.setGravity(Gravity.TOP, 0, 0);
        mToast.show();
    } 
 
    @Override 
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MSG_BRIGHTNESS_CHANGED: {
                onBrightnessChanged(msg.arg1, msg.arg2);
                break; 
            } 
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:setDuration, setView, show
 
public class Util { 
	public static Typeface tf;
 
	public static void raiseAToast(String text, int length, int color, Context context) {
		Toast toast = new Toast(context);
		LinearLayout toastLayout = new LinearLayout(context);
		toastLayout.addView(styleView(new TextView(context), text,
				25, color));
		toast.setView(toastLayout);
		toast.setDuration(length);
		toast.show();
	} 
	 
	public static View styleView(TextView view, String text, int size, int color) {
		view.setText(text);
		view.setTextSize(size);
		view.setTextColor(color);
		view.setTypeface(tf);
		view.setPadding(10, 10, 10, 10);
6
CodeRank
This code example shows how to use the following methods:getXOffset, getYOffset, setGravity, show
        } 
 
        // inform users of how long the timeout is now 
        final String toast = makeTimeoutToastString(context, screenTimeout);
        mToast = Toast.makeText(context, toast, Toast.LENGTH_LONG);
        mToast.setGravity(Gravity.CENTER, mToast.getXOffset() / 2, mToast.getYOffset() / 2);
        mToast.show();
    } 
 
    @Override 
    protected List<Uri> getObservedUris() {
        return OBSERVED_URIS;
    } 
 
    @Override 
    protected boolean handleLongClick(Context context) {
        Intent intent = new Intent("android.settings.DISPLAY_SETTINGS");
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
6
CodeRank
This code example shows how to use the following methods:setText, show
        } 
 
    public void run () 
        { 
        String sText =(((lcv++ % 2) == 0)  ? "Help me!" : "I've fallen down!" );
        toast.setText(sText);
        toast.show();
        if (rt != null)
            rt.play();
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:setDuration, setGravity, show
	} 
	 
	public void toast(String text, int length) {
		mText.setText(text);
 
		mToast.setGravity(Gravity.CENTER, 0, 0);
		mToast.setDuration(length);
		mToast.show();
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:setText, show
 
		if (lastText == null) {
			lastText = Toast.makeText(mapView.getContext(), text,
					Toast.LENGTH_LONG);
		} else { 
			lastText.setText(text);
		} 
		lastText.show();
 
	} 
 
	private void highlightSelectedOverlayItem(final int overlayIndex,
			final OverlayItem overlayItem) {
		if (selectedOverlayIndex != CURRENT_POSITION_OVERLAY_INDEX) {
			mOverlays.get(selectedOverlayIndex).setMarker(null);
		} 
		if (overlayIndex != CURRENT_POSITION_OVERLAY_INDEX) {
			overlayItem.setMarker(highlightMarker);
		} 
		Log.v(Constants.TAG, "highlighted. view should be redrawn");
5
CodeRank
This code example shows how to use the following methods:setGravity, show
        this.factory = factory;
 
        // Shows the tooltip if it's available. 
        if (getTag() != null) {
            tooltip = Toast.makeText(getContext(), (String) getTag(), Toast.LENGTH_SHORT);
            tooltip.setGravity(Gravity.CENTER, 0, 0);
            tooltip.show();
        } 
        doBegin(); 
    } 
 
    /** 
     * Ends the effect and then executes the runnable after the effect is finished. 
     */ 
    public void end(final Runnable runnableOnODone) {
        doEnd(); 
 
        // Wait till last output callback is done before finishing. 
        if ((lastFilterChangedCallback == null) || lastFilterChangedCallback.done) {
            finish(runnableOnODone);
6
CodeRank
This code example shows how to use the following methods:show
	// repository for created toasts 
	private Map<Long,Toast> mToasts = new HashMap<Long,Toast>();
	public void showToast(Long id) {
		Toast t = mToasts.get(id);
		if(t==null)
			mToasts.put(id, t = Toast.makeText(this, id.intValue(), Toast.LENGTH_SHORT));
		t.show();
	} 
 
	/* 
	 * represents the group currently selected, which persists between invocations.  
	 * this is not displayed with the Prefs activity. 
	 */ 
	private static final String GROUP_SELECTED = "groupSelected";
	public long getSelectedGroup() { 
		return mPrefs.getLong(GROUP_SELECTED, 0);
	} 
	 
	public void setSelectedGroup(long groupId) {
		mPrefs.edit().putLong(GROUP_SELECTED, groupId).commit();
6
CodeRank
This code example shows how to use the following methods:setText, show
        // Tell the user about what we did. 
        if (toast == null)
            toast = Toast.makeText(activity, msg,
                    Toast.LENGTH_LONG);
        else 
            toast.setText(msg);
        toast.show();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:setText, show
        // Tell the user about what we did. 
        if (toast == null)
            toast = Toast.makeText(activity, msg,
                    Toast.LENGTH_LONG);
        else 
            toast.setText(msg);
        toast.show();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:cancel, show
			textView.setText(Affichage);
			toast.show();}
		else{ 
			String Affichage_2 = textView.getText().toString();
			textView.setText(Affichage_2 + " \n" + Affichage);
			toast.cancel();
			toast.show();
			//myHandler2.removeCallbacks(Runnable2); 
			} 
 
		Runnable2 = new Runnable(){
			@Override 
			public void run() { 
				//Looper.prepare(); 
		    	toast.cancel();
		        Toast_ready=true;
			}}; 
 
		if(!Toast_ready) myHandler2.postDelayed(Runnable2, 4000);}
	 
6
CodeRank
This code example shows how to use the following methods:setText, show
     */ 
    public void showToast(String text) {
        if (mToast == null) {
            mToast = Toast.makeText(mContext, text, Toast.LENGTH_SHORT);
        } else { 
            mToast.setText(text);
        } 
        mToast.show();
    } 
 
    /** 
     * Show a Toast(Toast.LENGTH_SHORT). 
     *  
     * @param text 
     */ 
    public void showToast(int resId) {
        if (mToast == null) {
            mToast = Toast.makeText(mContext, resId, Toast.LENGTH_SHORT);
        } else { 
            mToast.setText(resId);
4
CodeRank
This code example shows how to use the following methods:show
                	sl.setVisibility(View.GONE);
                	webView.invalidate();
                	webView1.invalidate();
                    webView1.loadUrl("http://140.211.89.15/mobile/home.html");
            		if(count==0){
            			toast.show();
            			count++;
            		} 
                    return true; 
                } 
                return false; 
            } 
        }); 
        webView1.setWebViewClient(new MyWebViewClient());
         
         
        // Setup click listener 
        homeButton.setOnClickListener( new OnClickListener() {
        	public void onClick(View view) {
        		webView1.loadUrl("http://140.211.89.15/mobile/home.html");    		
5
CodeRank
This code example shows how to use the following methods:show
	 
	public static void runInUIThread(Context context, final Toast toast){
		final Activity activity = (Activity)context;
	      activity.runOnUiThread(new Runnable() {
	           public void run() { 
	        	   toast.show();
	           } 
	       }); 
	} 
	 
	public static Display getWindowDisplay(Context context){
		return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
	} 
	 
	public static String getPhoneNumber(Context context){
		TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		String phoneNumber = telephonyManager.getLine1Number();
		return phoneNumber;  
	} 
	 
5
CodeRank
This code example shows how to use the following methods:show
 
	public void login(Loginable loginable) {
		this.loginableRef = new WeakReference<Loginable>(loginable);
		if (idField.getText().toString().trim().equals("")
				|| pwdField.getText().toString().trim().equals("")) {
			toast.show();
		} else { 
			if (saveidCheckBox.isChecked()) {
				privateUtil.setSavedUserId(idField.getText().toString());
			} 
			session.loginWithDialog(getContext(), 
					idField.getText().toString(), 
					pwdField.getText().toString(), 
					loginableRef.get());
		} 
	} 
 
	public void loginViaTwitter(View v){
		MeHttpRequest request = new MeHttpRequest(context);
		request.authorizeViaExternalService(context, Service.TWITTER);
4
CodeRank
This code example shows how to use the following methods:show
    } 
 
    @Override 
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_UP) {
            mToast.show();
        } 
        return super.dispatchTouchEvent(ev);
    } 
} 
4
CodeRank
This code example shows how to use the following methods:show
    { 
    	if(!gpsWaiting)
    	{ 
    		gpsWaiting=true;
    		toast=Toast.makeText(ctx, "Waiting for GPS...", Toast.LENGTH_LONG);
    		toast.show();
    	} 
    } 
     
    public void cancelGPSWaiting() 
    { 
    	gpsWaiting=false;
    	if(toast!=null)
    		toast.cancel();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:show
        mContent.setPadding(p, p, p, p); 
 
        mContent.setOnClickListener(new View.OnClickListener() { 
            @Override 
            public void onClick(View v) { 
                mToast.show(); 
            } 
        }); 
 
        mContent.setOnLongClickListener(new View.OnLongClickListener() { 
            @Override 
            public boolean onLongClick(View v) { 
                try { 
                    startActivity(new Intent(Intent.ACTION_MAIN) 
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
                            | Intent.FLAG_ACTIVITY_CLEAR_TASK 
                            | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) 
                        .setClassName("com.android.settings","com.android.settings.pac.PACCircus")); 
                } catch (ActivityNotFoundException ex) { 
                    android.util.Log.e("PACLogoActivity", "Couldn't find a circus of PAC's."); 
4
CodeRank

Related Toast show Questions & Answers:

Other Toast show Examples

41:	  @Override
42:	  public boolean onOptionsItemSelected(MenuItem item) {
43:	    Toast.makeText(this, "Just a test", Toast.LENGTH_SHORT).show();
44:	    return true;
45:	  }

Read More

73:	  public void onProviderEnabled(String provider) {
74:	    Toast.makeText(this, "Enabled new provider " + provider,
75:	        Toast.LENGTH_SHORT).show();
76:	
77:	  }
-
80:	  public void onProviderDisabled(String provider) {
81:	    Toast.makeText(this, "Disabled provider " + provider,
82:	        Toast.LENGTH_SHORT).show();
83:	  }
84:	}

Read More

24:	        .hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
25:	      Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG)
26:	          .show();
27:	    } else {
28:	      cameraId = findFrontFacingCamera();
-
29:	      if (cameraId < 0) {
30:	        Toast.makeText(this, "No front facing camera found.",
31:	            Toast.LENGTH_LONG).show();
32:	      } else {
33:	        camera = Camera.open(cameraId);

Read More

67:						Toast.makeText(getApplicationContext(),
68:								"Please enter category name", Toast.LENGTH_SHORT)
69:								.show();
70:					}
71:				}

Read More

42:						Toast.makeText(getApplicationContext(),
43:								"Please enter category name", Toast.LENGTH_SHORT)
44:								.show();
45:					}
46:				}

Read More

76:				Toast.makeText(getApplicationContext(),
77:						"Sorry! Your device doesn't support camera",
78:						Toast.LENGTH_LONG).show();
79:				// will close the app if the device does't have camera
80:				finish();
-
164:					Toast.makeText(getApplicationContext(),
165:							"User cancelled image capture", Toast.LENGTH_SHORT)
166:							.show();
167:				} else {
168:					// failed to capture image
-
169:					Toast.makeText(getApplicationContext(),
170:							"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
171:							.show();
172:				}
173:			} else if (requestCode == CAMERA_CAPTURE_VIDEO_REQUEST_CODE) {
-
180:					Toast.makeText(getApplicationContext(),
181:							"User cancelled video recording", Toast.LENGTH_SHORT)
182:							.show();
183:				} else {
184:					// failed to record video
-
185:					Toast.makeText(getApplicationContext(),
186:							"Sorry! Failed to record video", Toast.LENGTH_SHORT)
187:							.show();
188:				}
189:			}

Read More

show Method Overview
Show the view for the specified duration.
See Code Examples for other Android Toast Methods: