How to know if a Fragment is Visible?

前端 未结 10 1951
闹比i
闹比i 2020-12-01 06:07

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? Th

10条回答
  •  自闭症患者
    2020-12-01 06:35

    If you want to know when use is looking at the fragment you should use

    yourFragment.isResumed()
    

    instead of

    yourFragment.isVisible()
    

    First of all isVisible() already checks for isAdded() so no need for calling both. Second, non-of these two means that user is actually seeing your fragment. Only isResumed() makes sure that your fragment is in front of the user and user can interact with it if thats whats you are looking for.

提交回复
热议问题