用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()来获得参数、

你可能感兴趣的:(用FragmentActivity实现点击跳转Fragment效果(未完))