http://developer.android.com/guide/topics/ui/notifiers/toasts.html
A toast is a view that displays a message to a user. It fills the space required for the message and the current activity remains visible and interactive.
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Register button
final Button button = (Button) findViewById(R.id.button);
// Set on click listener
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Toast.makeText(MainActivity.this, "toast message",
Toast.LENGTH_LONG).show();
}
});
}
}
Note:
The Toast class provides two public static makeText methods with which you can construct your toast object and message.
If you use a named toast, instead of an anonymous toast, you can set various attributes in code.
Example:
Toast toast = new Toast(getApplicationContext());
toast.setGravity(gravity, xOffset, yOffset);
http://developer.android.com/reference/android/widget/Toast.html