Friday, June 29, 2012

Android Toast notification show Different Gravity.

Android Toast notification show Different Gravity.
Android  toast notification is a message that pops up on the surface of the window. It only fills the amount of space required for the message and the user's current activity remains visible and interactive. The notification automatically fades in and out, and does not accept interaction events.
Toast notify we can show in different gravity like "TOP", "RIGHT", "LEFT", "BOTTOM".etc.. Below i added code..

import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.Gravity;
import android.widget.Toast;
public class AndroidQAActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast t = Toast.makeText(AndroidQAActivity.this, "Hi Buddy", Toast.LENGTH_LONG);

t.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0); 
t.show();
Toast t1 = Toast.makeText(AndroidQAActivity.this, "Hi Buddy", Toast.LENGTH_LONG);
t1.setGravity(Gravity.CENTER, 0, 0);
t1.show();
Toast t2 = Toast.makeText(AndroidQAActivity.this, "Hi Buddy", Toast.LENGTH_LONG);
t2.setGravity(Gravity.BOTTOM, 0, 0);
t2.show();
}
}

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...