Posted By

Vetromilla on 11/01/11


Tagged

simple message alert android toast


Versions (?)

Simple alert for Android


 / Published in: Java
 

Displays a simple alert using Toast

  1. import android.content.Context;
  2. import android.widget.Toast;
  3. import android.view.Gravity;
  4.  
  5. public static void alert(Context context, String message) {
  6. //New Toast Object with short duration
  7. Toast msg = Toast.makeText(context, message, Toast.LENGTH_SHORT);
  8.  
  9. //Setting the gravity to center position
  10. msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2, msg.getYOffset() / 2);
  11.  
  12. //Displaying the alert
  13. msg.show();
  14. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: peruggia on November 2, 2011

Thank you for that nice script, simple and clean.

You need to login to post a comment.