Android App应用启动欢迎页

大家都知道一个没有欢迎页的App给人的感觉就像人提了光头一样,很突兀,也很不友好,今天给大家分享一个及其简便的欢迎加载页

第一步,编写接口

interface ICSplash {
    
    

    interface IPSplash {
    
    

        fun init()
    }

    interface IVSplash : BaseView {
    
    

        fun jumpToMain()
    }
}

第二步 编写Presenter

注:没有用mvp模式的小伙伴也不用担心,直接把init方法拿走也能用,把 mView.jumpToMain()修改成你要执行的操作
class SplashPresenter constructor(private val mProvider: LifecycleProvider<ActivityEvent>,
                                  private val mView: ICSplash.IVSplash) : ICSplash.IPSplash {
    
    

    override fun init() {
    
    
        Observable.timer(1500, TimeUnit.MILLISECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .compose(mProvider.bindToLifecycle())
                .subscribe {
    
     mView.jumpToMain() }
    }
}
第三步,编写Activity
class SplashActivity : BaseActivity(), ICSplash.IVSplash {
    
    

    override val layout = R.layout.a_splash

    override fun initPresenter() {
    
    
        SplashPresenter(this, this).init()
    }

    override fun jumpToMain() {
    
    

	//动画加载完成之后需要执行操作,比如跳转Activity
    }
    override fun showError(msg: String) {
    
    
        ToastUtils.showShort(msg)
    }
}

猜你喜欢

转载自blog.csdn.net/qq_28643195/article/details/108366721