Is it possible to make Customize Toast in Android. like if can we place in it image icon and place button.
You can also use the regular makeText() and handle the getView() to set an image next to see the next.
Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
TextView tv = (TextView) toast.getView().findViewById(android.R.id.message);
if (null!=tv) {
tv.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
tv.setCompoundDrawablePadding(context.getResources().getDimensionPixelSize(R.dimen.padding_toast));
You can put any view in a Toast using setView. However, I'm not quite sure why you would want to place a button in it, as a Toast will rapidly disappear. Taken from the officiel developer site :
When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see.
So the toast should only be used to display information. For more complex interactions, you can use a Dialog.
Toast is non focus able.Adding button did not make sense. However you can display information.You can also control its visibility means u can hide and show by making few changes in Toast class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With