Anko Preview plugin is available for IntelliJ IDEA and Android Studio. It allows you to preview AnkoComponent
classes written with Anko directly in the IDE tool window.
The Anko Preview plugin currently does not support Android Studio 2.2+ or IntelliJ IDEA 2016.3+.
You can download Anko Preview plugin here.
Suppose you have these classes written with Anko:
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
MyActivityUI().setContentView(this)
}
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>) = ui.apply {
verticalLayout {
val name = editText()
button("Say Hello") {
onClick { ctx.toast("Hello, ${name.text}!") }
}
}
}.view
}
Put the cursor somewhere inside the MyActivityUI
declaration, open the Anko DSL Preview tool window ("View" → "Tool Windows" → "Anko DSL Preview") and press Refresh.
Running make is required, so it could take some time before the image will be actually shown.
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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。