测试Fragment代码
class TestFragment : MallFragment() { override fun setLayout(): Any { return R.layout.fragment_test } override fun onBindView(savedInstanceState: Bundle?, rootView: View) { Toast.makeText(context, "初始化完成", Toast.LENGTH_SHORT).show() } }
class MainActivity : ProxyActivity() { override fun setRootFragment(): MallFragment { return TestFragment() } }
ProxyActivity代码
abstract class ProxyActivity : AppCompatActivity(), ISupportActivity { private lateinit var mDelegate: SupportActivityDelegate abstract fun setRootFragment(): MallFragment override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mDelegate = SupportActivityDelegate(this) mDelegate.onCreate(savedInstanceState) initContainer(savedInstanceState) } private fun initContainer(savedInstanceState: Bundle?) { val container = FrameLayout(this) container.id = R.id.fragment_container setContentView(container) if (savedInstanceState == null) { mDelegate.loadRootFragment( R.id.fragment_container, setRootFragment() ) } } override fun onDestroy() { mDelegate.onDestroy() super.onDestroy() System.gc() System.runFinalization() } override fun getSupportDelegate(): SupportActivityDelegate { return mDelegate } override fun post(runnable: Runnable?) { mDelegate.post(runnable) } override fun extraTransaction(): ExtraTransaction { return mDelegate.extraTransaction() } override fun getFragmentAnimator(): FragmentAnimator { return mDelegate.fragmentAnimator } override fun setFragmentAnimator(fragmentAnimator: FragmentAnimator) { mDelegate.fragmentAnimator = DefaultHorizontalAnimator() } override fun onCreateFragmentAnimator(): FragmentAnimator { return mDelegate.onCreateFragmentAnimator() } override fun onBackPressedSupport() { mDelegate.onBackPressedSupport() } override fun onBackPressed() { mDelegate.onBackPressed() } }
慕斯4360584