JayVDiyk JayVDiyk - 5 months ago 12
Android Question

Create a Toast that Comes From Top of Screen

I am wondering how do we create a Custom toast in Android that shows on the top of screen like this?

enter image description here

I came from iOS background and now I have to create custom controls like this.

Any pointers please?

Thank you

Answer

Check this link: https://github.com/gfranks/GFMinimalNotifications, this is what you want i think and it is working fine for me.

output:

enter image description here

Or you can prepare custom toast like this:

View layout = getLayoutInflater().inflate(R.layout.customtoast,
            (ViewGroup) findViewById(R.id.custom_toast_layout));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, 0, 0);
toast.setView(layout);
toast.show();