Simple alert for Android


/ Published in: Java
Save to your folder(s)

Displays a simple alert using Toast


Copy this code and paste it in your HTML
  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

You need to login to post a comment.