Issue
How to implement toast with button as shown below? It is used in recent Google apps in Android.
Solution
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);
}
}
Answered By - Gunaseelan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.