【53】Kotlin android 插件Kotlin

编程入门 行业动态 更新时间:2024-10-08 13:29:01

【53】Kotlin android <a href=https://www.elefans.com/category/jswz/34/1771202.html style=插件Kotlin"/>

【53】Kotlin android 插件Kotlin

module:app -> build.gradle 添加以下代码

apply plugin: 'kotlin-android-extensions'

布局代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android=""xmlns:app=""xmlns:tools=""android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/helloTv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>

 java代码

class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)helloTv.text = "Hello Kotlin!"}
}

看 不用再使用findViewById了。而且会自动强转成对应的类型

这简直就是我从开发的时候就梦寐以求的东西

这也是kt追求的东西

更多推荐

【53】Kotlin android 插件Kotlin

本文发布于:2024-03-08 00:10:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1719322.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插件   Kotlin   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!