I'm using the support library v4 and my questions are, How to know if a Fragment is Visible? and How can I change the propierties of the Layout inflated in the Fragment? Thanks in advance.
---Edit---
I'm using fragments like in the android developers tutorial with a FragmentActivity
Both
isVisible()
andisAdded()
returntrue
as soon as theFragment
is created, and not even actually visible. The only solution that actually works is:This does the job. Period.
You can override setMenuVisibility like this:
You should be able to do the following:
If you want to know when use is looking at the fragment you should use
instead of
First of all
isVisible()
already checks forisAdded()
so no need for calling both. Second, non-of these two means that user is actually seeing your fragment. OnlyisResumed()
makes sure that your fragment is in front of the user and user can interact with it if thats whats you are looking for.you can try this way:
or
In this if, you check if currentFragment is instance of YourFragment
getUserVisibleHint()
comes as true only when the fragment is on the view and visible