Let's start with a simple example where we use Anko to create a layout for our target activity (the activity in which you want to create a layout):
- Here's the code for the onCreate() method that you need to put in your target activity:
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) verticalLayout { padding = dip(20) val name = editText { hint = "What is your name?" } val message = editText { hint = "Your message" } button("Send") { onClick { toast("Hello, ${name.text} we have recorded your message!") } } }}
- Basically, in the preceding code, we want to create a basic "contact us" form. For this, we have created a vertical linear layout with a 20 dip padding and, inside the vertical ...