0

is there a way to get the View on the screen if it's visible or not giving the resource id for example if i have a button id in the xml is "@id/save"

passing "save" id can we get if the view is currently visible or not from any where in the app.

Marcel Adel
  • 181
  • 2
  • 12

1 Answers1

2
findViewById(R.id.save).isShown()

from any where in the app

Finding any view only makes sense for a single activity/fragment/dialog/ViewGroup. You can reuse the same view id across multiple screens to represent completely different view types.

I'm not sure it makes sense to know if a button is visible for a screen that doesn't have the view, so you'll need to add a null check to the above line.

If you want to put your button in some dialog box, then you would check if the dialog is present

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • That's a good start but it won't check whether the view has been scrolled off the screen. Also, what about the "from any where in the app" part of OP's question? – Ted Hopp Feb 01 '18 at 14:25
  • For scrolling, probably https://stackoverflow.com/questions/14039454/how-can-you-tell-if-a-view-is-visible-on-screen-in-android – OneCricketeer Feb 01 '18 at 14:27