美文网首页
判断fragment显示和隐藏,判断fragment是否在前台

判断fragment显示和隐藏,判断fragment是否在前台

作者: 努力深耕Android的小透明 | 来源:发表于2018-11-13 17:44 被阅读49次

    addFragment或者replaceFrament

    @Override
    public void onResume() {
        super.onResume();
        //TODO now visible to user
    }
    @Override
    public void onPause() {
        super.onPause();
        //TODO now invisible to user
    }
    

    使用show和hide来显隐的Fragment

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(hidden){
            //TODO now invisible to user
        } else {
            //TODO now visible to user
        }
    }
    @Override
    public void onPause() {
        super.onPause();
        //TODO now visible to user
    }
    

    在ViewPager中的Fragment

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser){
            //TODO now it's visible to user
        } else {
            //TODO now it's invisible to user
        }
    }
     @Override
    public void onResume() {
        super.onResume();
       //TODO now it's visible to user
    }
    
    @Override
    public void onPause() {
        super.onPause();
        //TODO now it's invisible to user
    }
    
    

    相关文章

      网友评论

          本文标题:判断fragment显示和隐藏,判断fragment是否在前台

          本文链接:https://www.haomeiwen.com/subject/vdilfqtx.html