Vaibhav Maheshwari
Vaibhav Maheshwari

Reputation: 384

How to attach onClickListener to an invisible view

I want to attach an onClickListener to an ImageView which is made INVISIBLE. I know I could set it to the TRANSPARENT color but due to certain reasons I don't want to do that and an INVISIBLE ImageView is not listening to clicks. Is there any way to achieve the required thing?

Upvotes: 3

Views: 1208

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93678

No, INVISIBLE views don't receive touch events. However there are a few alternatives you can use:

  • Set the view's alpha to 0. This would make it fully transparent.
  • Create a 2nd view of the exact same size above the view and put the click handler on that.
  • Put a touch handler on the parent and check if in the area of the invisible view when you detect a click.

Least work is probably top to bottom on that list.

Upvotes: 12

Related Questions