在实现架构组件时,我面临这个问题
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleOwner
import android.os.Bundle
import com.reversebits.trendyvidz.R
class MainActivity : LifecycleOwner {
override fun getLifecycle(): Lifecycle {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme) //This shows error
setContentView(R.layout.activity_main) //This shows error
init()
}
private fun init() {
when {
isNetworkAvailable() -> toast("Yes Avail")
else -> toast("No")
}
}
}
我如何想在这里获得像setContentView()
AppCompatActivity 这样的基于 Activity 上下文的方法?