用FragmentActivity实现点击跳转Fragment效果(未完)

因为TabHost已经不推荐使用了,所以现在一般都用FragmentTabHost,但是因为Fragment在3.0才出现,所以为了解决低版本兼容问题。我们要引入android.support.v4.app包!注意:当你导入跟FragmentTabHost相关包时,都要导成android.support.v4.app包!不然会报错不能兼容。

简单说一下v4兼容包,其算是android最低等级的支持包。其中它的支持包主要为:
1.Fragment
英文:
class overview:
Static library support version of the framework’s Fragment. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework’s implementation. See the framework Fragment documentation for a class overview.

The main differences when using this support version instead of the framework version are:

Your activity must extend FragmentActivity
You must call getSupportFragmentManager() to get the FragmentManager
主要方法:
1.final FragmentActivity getActivity()
Return the FragmentActivity this fragment is currently associated with.
2.final FragmentManager getChildFragmentManager()
Return a private FragmentManager for placing and managing Fragments inside of this Fragment.
3.final FragmentManager getFragmentManager()
Return the FragmentManager for interacting with fragments associated with this fragment’s activity.(与其他fragment通信)
4.final Fragment getTargetFragment()
Return the target fragment set by setTargetFragment(Fragment, int).
5.final int getTargetRequestCode()
Return the target request code set by setTargetFragment(Fragment, int).
6.View getView()
Get the root view for the fragment’s layout (the one returned by onCreateView(LayoutInflater, ViewGroup, Bundle)), if provided.
7.static Fragment instantiate(Context context, String fname, Bundle args)
Create a new instance of a Fragment with the given class name.
8.void onActivityCreated(Bundle savedInstanceState)
Called when the fragment’s activity has been created and this fragment’s view hierarchy instantiated.
构造函数:
对于构造函数来说,强烈建议不要重载带有参数的构造函数,因为Fragment重新实例化并不会调用带参构造函数。对于需要参数的情况,应该在构造fragment后立即书写setArguments(Bundle),这个Bundle会跨越fragment的销毁和重生,通过getArguments()来获得参数、

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值