● 依賴:compile 'org.jetbrains.anko:anko:0.10.0' ● 界面: import android.view.View import org.jetbrains.anko.* import org.jetbrains.anko.sdk25.coroutines.on ...
● 依賴:compile 'org.jetbrains.anko:anko:0.10.0'
● 界面:
import android.view.View import org.jetbrains.anko.* import org.jetbrains.anko.sdk25.coroutines.onClick class MainActivityUI : AnkoComponent<MainActivity> { override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { verticalLayout { padding = dip(10) var name = textView("Hello World") { padding = dip(10) } button("更換文字") { onClick { name.text = "Anko Demo" } } } } }
● Activity:
import android.os.Bundle import android.support.v7.app.AppCompatActivity import org.jetbrains.anko.setContentView class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MainActivityUI().setContentView(this) } }