SoFunction
Updated on 2025-04-08

Android Toast prompts to encapsulate instance code

Android Toast prompt packaging

Toast prompts are often used in Android. There are many Toast prompts in the project. Write a very long line, simply encapsulate it, and propose the Toast method, which is very convenient to use:

Example code:

/**
    * Prompt string
    * short Toast
    * @param context
    * @param text
    * by Hankkin at:2015-10-07 21:14:43
    */ 
  public static void showToast(Context context, String text) { 
    Toast toast = (context,text,Toast.LENGTH_SHORT); 
    (,0,0); 
    (); 
  } 
  /**
    * Prompt string
    * short Toast
    * @param context
    * @param text
    * by Hankkin at:2015-10-07 21:14:43
    */ 
  public static void showLToast(Context context, String text) { 
    Toast toast = (context, text, Toast.LENGTH_LONG); 
    (, 0, 0); 
    (); 
  } 
 
  /**
    * Prompt to associate strings according to ResId
    * short Toast
    * @param context
    * @param resId
    * by Hankkin at:2015-10-07 21:14:43
    */ 
  public static void showToast(Context context, int resId) { 
    Toast toast = (context, resId, Toast.LENGTH_SHORT); 
    (, 0, 0); 
    (); 
  } 
 
  /**
    * Prompt to associate strings according to ResId
    * often long toast
    * @param context
    * @param resId
    * by Hankkin at:2015-10-07 21:14:43
    */ 
  public static void showLToast(Context context, int resId) { 
    Toast toast = (context, resId, Toast.LENGTH_LONG);; 
    (, 0, 0); 
    toast. 

Thank you for reading, I hope it can help you. Thank you for your support for this site!