문제

I have a custom toast diplaying an image and some text. This toast is big enough to cover almost half of the screen. It has a duration of LENGTH_LONG because it contains much information.

In some cases this can be a bit annoying for the user. Is there any way to cancel the toast when the user clicks on it? If not, is there any way to cancel the toast when clicking anywhere outside the toast?

Thanks!

도움이 되었습니까?

해결책

Keep a reference of you Toast, you can then use the cancel() method, documentation here.

In order to know when you need to cancel the toast, you will need to intercept the touch event with the OnTouchEvent of your activity and get the position x/y of the touch event. Then you can compare it with myToast.getView().getY()and getX() to get the top left corner and getWidth() and getHeight().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top