Toast at the center of the screen – Android Tip # 2

By | October 29, 2018

Here is Tip # 2

Toast at Center of the Screen

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
              (ViewGroup) findViewById(R.id.custom_toast_layout));
text.setText("Toast at the Center of Screen");

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();

Leave a Reply

Your email address will not be published. Required fields are marked *