1 Star 0 Fork 0

yohom / anko

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
PREVIEW.md 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
Yan Zhulanow 提交于 2017-02-15 21:39 . Minor: Update PREVIEW

Anko Preview Plugin

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+.

Using Anko Preview Plugin

Installing the Plugin

You can download Anko Preview plugin here.

Preview

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.

XML to DSL Converter

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.

1
https://gitee.com/yohom_342/anko.git
git@gitee.com:yohom_342/anko.git
yohom_342
anko
anko
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891