android 3.0 kotlin开发(1) 引入 anko
现在android studio 3.0上可以用 kotlin 编写android移动应用
但是下载来这个黄黄的android studio 之后发现它并没有引入 anko
所以这需要手动引入吧...大概...是这样
下面说说引入步骤
1. 新建项目后找到自己的 build.gradle 文件插入以下代码,之后点击Sync Now
//anko
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile 'org.jetbrains.anko:anko-sdk15:0.9'
compile 'org.jetbrains.anko:anko-support-v4:0.9'
compile 'org.jetbrains.anko:anko-appcompat-v7:0.9'
build 跑完之后就引入ok
2.现在就引入成功了
更细节的引入可以参考它官方的 github
现在你就能享受 kotlin 的便利了
以下是使用实例
先在activit_main.xml中设置好id
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/myText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
然后进入MainAcitvity.kt插入
import kotlinx.android.synthetic.main.activity_main.*
现在请放松,你想要更改TextView时只需要写
myText.setText("ssss")
什么你说点击事件?
设置好Button的id之后你只需要
myBtn.onClick {
......
}
now…回头再看java,我的天我以前打的都是些什么鬼…