Thursday, February 21, 2019

Change Toast position

To send an information to user, we can use toast, for example, to inform that text in EditText doesn’t satify requirement.
Toast.makeText(class.this,"Data enter not valid", Toast.LENGTH_SHORT).show();

That toast will show at screen’s bottom. To set position at center screen , we use.
Toast toast = Toast.makeText(class.this, "Data enter not valid ",Toast.LENGTH_SHORT);       
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();

If you want to set it on top, change Gravity to Gravity.TOP

No comments:

Post a Comment