Kotlin 扩展函数 Activity 套Fragment

只是用于自己记录,方便以后查阅,就直接上代码了

/**Activity 套Fragment*/
inline fun  AppCompatActivity.addFragment(@IdRes containerViewId: Int) {
    supportFragmentManager.beginTransaction().add(containerViewId,
            newInstanceFragment()).commit()
}

/**Activity 套Fragment*/
inline fun  AppCompatActivity.replaceFragment(@IdRes containerViewId: Int) {
    supportFragmentManager.beginTransaction().replace(containerViewId,
            newInstanceFragment()).commit()
}

你可能感兴趣的:(Kotlin 扩展函数 Activity 套Fragment)