美文网首页
Fragment一些总结

Fragment一些总结

作者: 海在路上 | 来源:发表于2017-10-17 15:34 被阅读1次

>> Fragment 嵌套 Fragment时被嵌套Fragment的管理器。

FragmentManager  childFragmentManager = getChildFragmentManager();

// fragment中嵌套TabLayout时使用这个FragmentManager

>> Fragment放到Activity中时:

//支持 3.0以下android系统API版本

getsupportFragmentManager();

//支持 3.0以上android系统API版本

getFragmentManager();

>> 获取当前Activity中的某一个布局中的当前的Fragment

这种方法只适用<fragment/>,也就是静态添加的情况。

Fragment  fm = getSupportFragmentManager().findFragmentById(R.id.fragment_container)

getSupportFragmentManager().findFragmentByTag("myfragment"));

>> 子Fragment获取父Fragment。

 ((ParentFragment)(ChildFragment.this.getParentFragment())).changeLayout(); 

>> Fragment的hide和show的回调回调

/**

* Called when the hidden state (as returned by {@link #isHidden()} of

* the fragment has changed.  Fragments start out not hidden; this will

* be called whenever the fragment changes state from that.

* @param hidden True if the fragment is now hidden, false otherwise.

*/

public void onHiddenChanged(boolean hidden) {

}

>>  在activity中获取Fragment中的控件

getFragmentManager().findFragmentById(id).getView().findViewById(id);

相关文章

网友评论

      本文标题:Fragment一些总结

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