How to check if a button is visible?

Asked

Viewed 421 times

2

I would like to know if it is possible to use a condition operator, such as if, to check whether a button is visible or not. If that’s how can I implement it? I made a few attempts using is.Enable but was unsuccessful.

1 answer

4

If it is visibility you need to test you can use the method getVisibility view-class. The method exists in the class View but how Button derives from View, can use it directly.

The code would look like this:

if (meuBotao.getVisibility() == View.VISIBLE) {
    //código para quando está visivel
}

It has 3 visibility states that can test:

  • View.VISIBLE
  • View.INVISIBLE
  • View.GONE

Documentation for the view class and to the button class

Browser other questions tagged

You are not signed in. Login or sign up in order to post.