Saturday 24 August 2013

How to show custom toast below ActionBar

How to show custom toast below ActionBar

How can I show a custom Toast just below ActionBar (compatible with API7)?
A method which creates the Toast is as follows:
public void showToast(Activity context, String text) {
LayoutInflater inflater = context.getLayoutInflater();
View layout = inflater.inflate(R.layout.popup, null);
TextView tv = (TextView)layout.findViewById(R.id.popup);
tv.setText(text);
Toast toast = new Toast(context);
toast.setGravity(Gravity.FILL_HORIZONTAL, 0, Y);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
Actually, in order to be able to call this method from any activity, I put
it in my Application class. As I understand, I need to put Y (top offset)
to toast.SetGravity(). But I have no idea how to get the correct top
coordinate of activity's layout, which is "ActionBar bottom". Any help
would be highly appreciated!

No comments:

Post a Comment