● 依赖: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) } }
时间: 2024-10-13 02:50:09