Search code examples
androidandroid-framelayoutcircularreveal

How to setVisibility within class extending FrameLayout?


I have a FAB class extending FrameLayout where I want to have a hide method which implements the reveal effect. Therefore I need to set the visibility to INVISIBLE:

public class FloatingActionButton extends FrameLayout implements Checkable {
    ...
    private void hide() {
        ...
            this.setVisibility(View.INVISIBLE);
        ...
        hideFabAnimator.start();
    }
}

But I get an error when trying to call setVisibility() on 'this' : "Cannot resolve method 'setVisibilty(int)'".


Solution

  • Seems that this.setVisibility(View.INVISIBLE); is located inside another class. It this case FloatingActionButton.this.setVisibility(View.INVISIBLE) will solve your issue.

    You can find explanation here.