abstract class BaseFragment :Fragment(){ override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val rootView = layoutInflater.inflate(getResourcesId(), container, false) //初始化控件字段 initView(rootView) return rootView } open fun initView(rootView: View){//不添加open不能被重写 } abstract fun getResourcesId(): Int//加上abstract表示要子类实现 }