以toast显示。
- inner class UI : AnkoComponent<LoginActivity> {
- override fun createView(ui: AnkoContext<LoginActivity>): View {
- return with(ui){
- verticalLayout {
- val textView=textView("我是一个TextView"){
- textSize = sp(17).toFloat()
- textColor=context.resources.getColor(R.color.red)
- }.lparams{
- margin=dip(10)
- height= dip(40)
- width= matchParent
- }
- val name = editText("EditText")
- button("Button") {
- onClick { view ->
- toast("Hello, ${name.text}!")
- }
- }
- }
- }
- }
- }
然后在onCreate办法中加一句代码,即可创建我们的构造页面了。如下