Tuesday, 17 June 2014

how to use custom toast in android

public static void displayToast(Activity ctx, String title) {

LayoutInflater inflater = ctx.getLayoutInflater();
View layout = inflater.inflate(R.layout.customtoast,
(ViewGroup) ctx.findViewById(R.id.toast_layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(title);
Toast toast = new Toast(ctx);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(1500);
toast.setView(layout);
toast.show();
}

No comments:

Post a Comment