RxFragmentTool.java 2.46 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
package com.yidianling.common.tools;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

/**
 * Created by vondear on 2016/12/26.
 */

public class RxFragmentTool {

    //----------------------------------------------------------------------------------------------Fragment的静态使用 start
    //在布局文件中直接使用标签
    /*    <fragment
            android:layout_below="@id/id_fragment_title"
            android:id="@+id/id_fragment_content"
            android:name="com.zhy.zhy_fragments.ContentFragment"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />*/

    //==============================================================================================Fragment的静态使用 end

    //----------------------------------------------------------------------------------------------Fragment的动态使用 start

    /**
     * v4包下的使用
     * 动态的使用Fragment
     *
     * 在布局文件中使用 FrameLayout 标签
     *
     * @param fragmentActivity
     * @param fragment
     * @param r_id_fragment    <FrameLayout android:id="@+id/r_id_fragment"/>
     */
    public static void showFragment(FragmentActivity fragmentActivity, Fragment fragment, int r_id_fragment) {
        FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(r_id_fragment, fragment);
        fragmentTransaction.commit();
    }

    /**
     * android.app.Activity下的使用
     * 动态的使用Fragment
     *
     * 在布局文件中使用 FrameLayout 标签
     *
     * @param activity
     * @param fragment
     * @param r_id_fragment <FrameLayout android:id="@+id/r_id_fragment"/>
     */
    public static void showFragment(Activity activity, android.app.Fragment fragment, int r_id_fragment) {
        android.app.FragmentManager fragmentManager = activity.getFragmentManager();
        android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(r_id_fragment, fragment);
        fragmentTransaction.commit();
    }

    //==============================================================================================Fragment的动态使用 start
}