I'm trying to use a Custom Toast with ImageView
and TextView
.
I want my Toast to disappear when I touch anywhere (clicking button, touching layout...), but it doesn't.
I read the Toast.class
file and tried using the cancel()
method before a new Toast was called, but that didn't solve anything. Can anyone give me a solution?
My CustomToast.java
:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View v = new View(context);
v = inflater.inflate(R.layout.custom_toast, (ViewGroup) v.findViewById(
R.id.layout_custom_toast));
layout = (RelativeLayout) v.findViewById(R.id.layout_custom_toast);
tvToast = (TextView) v.findViewById(R.id.tv_custom_toast);
tvToast.setText(text);
ivToast = (ImageView) v.findViewById(R.id.iv_custom_toast);
layout.setBackgroundResource(R.drawable.border_style_red);
ivToast.setBackgroundResource(R.drawable.warning);
Toast toast = new Toast(context);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(v);
toast.show();