Anko Preview plugin is available for IntelliJ IDEA and Android Studio. It allows you to preview Activity
and Fragment
classes written with Anko directly in the IDE tool window.
You can download Anko Preview plugin here.
Suppose you have this class written with Anko:
public class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
verticalLayout {
val name = editText()
button("Say Hello") {
onClick { toast("Hello, ${name.text}!") }
}
}
}
}
Put the cursor somewhere inside the MyActivity
declaration, open the DSL Preview tool window ("View" → "Tool Windows" → "DSL Preview") and press Refresh.
Module make is required, so it could take some time before the image will be actually shown.
🐧 | Some dependencies (around 30 MB) are loaded during the first refresh. |
Plugin also supports converting layouts from the XML format to Anko DSL code. Open an XML file and select "Code" → "Convert to Anko DSL". You can convert several XML layout files simultaneously.