How to implement toast with button as shown below? It is used in recent Google apps in Android.
Asked
Active
Viewed 381 times
-1
-
2for ref: [Customize toast](http://www.learn-android-easily.com/2013/05/customiozing-toast-in-android.html) and an [SO question link regarding the same](http://stackoverflow.com/questions/16909476/how-to-customize-toast-in-android?rq=1) – Pararth Jun 04 '14 at 06:43
-
[http://stackoverflow.com/questions/9575520/how-can-i-include-a-button-in-a-toast-notification](http://stackoverflow.com/questions/9575520/how-can-i-include-a-button-in-a-toast-notification) – M D Jun 04 '14 at 06:45
-
It's usually referred to as the [Undo Bar](https://plus.google.com/+RomanNurik/posts/RA9WEEGWYp6). – adneal Jun 04 '14 at 06:45
1 Answers
0
You can use custom toast messages like this. This is a dialog will dismiss after 2.5 seconds just like a toast.
public class CustomToast extends Dialog {
public CustomToast(Context context, String text) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(android.content.Context.
LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.toast, null);
TextView tv = (TextView) layout.findViewById(R.id.toastText);
tv.setText(text);
setContentView(layout);
show();
setCanceledOnTouchOutside(true);
setCancelable(true);
Window window = getWindow();
window.setGravity(Gravity.BOTTOM);
new Handler().postDelayed(new Runnable() {
public void run() {
dismiss();
}
}, 2500);
}
}

Bhargav Rao
- 50,140
- 28
- 121
- 140

Gunaseelan
- 14,415
- 11
- 80
- 128