Android Toast - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:setDuration, setGravity, setView, show
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:finish, startActivity, setClass, makeText
 
    protected void onPostExecute(String message) {
        dialog.hide();
        dialog.cancel();
 
        Toast.makeText(context,message,Toast.LENGTH_LONG).show();
 
		Intent i = new Intent().setClass(context, TabWidget.class);
		context.startActivity(i);
 
        context.finish();
    } 
} 
7
CodeRank
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:getResources, makeText
 
        final Context context = view.getContext();
        final int viewWidth = view.getWidth();
        final int viewHeight = view.getHeight();
        final int viewCenterX = screenPos[0] + viewWidth / 2;
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS
                * context.getResources().getDisplayMetrics().density);
 
        Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        boolean showBelow = screenPos[1] < estimatedToastHeight;
        if (showBelow) {
            // Show below 
            // Offsets are after decorations (e.g. status bar) are factored in 
            cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL,
                    viewCenterX - screenWidth / 2,
                    screenPos[1] - displayFrame.top + viewHeight);
        } else { 
            // Show above 
            // Offsets are after decorations (e.g. status bar) are factored in 
7
CodeRank
This code example shows how to use the following methods:runOnUiThread, getString, makeText
     * @param resId The resource identifier of the message string 
     * @param formatArgs The format arguments that will be used for substitution. 
     */ 
    public static void showToast( Activity activity, int resId, Object... formatArgs )
    { 
        showToast( activity, activity.getString( resId, formatArgs ) );
    } 
     
    /** 
     * Pop up a temporary message on the device. 
     * @param activity The activity to display from 
     * @param message The message string to display. 
     */ 
    public static void showToast( Activity activity, String message )
    { 
        if( activity == null )
            return; 
         
        if( sToast != null )
        { 

7
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);
7
CodeRank
This code example shows how to use the following methods:finish, makeText
    } 
     
    @Override 
    protected void onPostExecute(Void unused) {
      if (text!=null) {
        Toast.makeText(host, text, Toast.LENGTH_SHORT).show();
      } 
       
      host.finish();
    } 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:getSharedPreferences, startActivity, makeText
		} else if (intent.getStringExtra("unregistered") != null) {
			Log.d("c2dm", "unregistered");
 
		} else if (registration != null) {
 
			Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
			editor.putString(REGISTRATION_KEY, registration);
			System.out.println(registration);
			editor.commit();
 
			Intent accountIntent = new Intent(context,AccountList.class);
			accountIntent.putExtra("regKey",registration) ;
			accountIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
			context.startActivity(accountIntent);
		} 
		Toast.makeText(context, registration, Toast.LENGTH_LONG);
	} 
 
	private void handleMessage(Context context, Intent intent)
	{ 
		Log.v(TAG,"handleMessage");
6
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

Related Android Toast Questions & Answers:

See Code Examples for Android Toast Methods: