Russell
Russell

Reputation: 358

Android : Click through Toast

Upon clicking a button, a toast(with image) appears. This toast appears on top of another button. Now i want to click this another button while Toast is still there. It takes some time for the toast to disappear. Meanwhile if user wants to click the button under this Toast, he should be able to. Currently Toast blocks it.

Is there a method by which i can pass the click through the Toast ? Any other better approach ?

(I don't want to play with the timing of Toast appearing or disappearing..)

Upvotes: 4

Views: 2570

Answers (4)

kapil thadani
kapil thadani

Reputation: 1425

A toast can not be clicked. It is not possible to capture a click inside a toast message. You will need to build a dialog for that. Look at Creating Dialogs for more info.

The API on the Toast class state that a toast will never receive the focus and because a toast is not a view there is no onClick message. I would assume that therefore childs of a Toast can not be clicked as well.

Upvotes: 0

GrIsHu
GrIsHu

Reputation: 23638

A Toast will never be clickable. Its not possible to get the focus of the Toast and capture a click event of any view inside a `Toast.

You can create a dialog for that to get the click event.

The API on the Toast class state that a toast will never receive the focus and because a toast is not a view there is no onClick message. I would assume that therefore childs of a Toast can not be clicked as well.

For more details check out Use Image Buttons and Toast in Android

Upvotes: 0

nikvs
nikvs

Reputation: 1090

You can show the toast in a different location so that it does not get in the way of your second button. You can achieve this by setting gravity for your toast. sample-

toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);

Upvotes: 0

Madhur Ahuja
Madhur Ahuja

Reputation: 22691

Use Crouton library instead of Toasts

https://github.com/keyboardsurfer/Crouton

Upvotes: 1

Related Questions