Hello Kotlin
来源:互联网 发布:出国语言软件 编辑:程序博客网 时间:2024/05/22 14:04
Kotlin初步学习笔记
优缺点就不讲了百度多得是,只说怎么上手吧。
目前Android Studio 最低3.0才支持Kotlin,下载解压之后运行,选择创建Kotlin项目
待项目构建完成后,在你module的build.gradle文件中添加如下代码
apply plugin: 'kotlin-android-extensions'
如下图,第二行是构建项目的时候创建的
这样,配置方面算是OK了
开始写代码!
写两个控件方便演示
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.daniel.kotlindemo.MainActivity"> <TextView android:id="@+id/tv_show" 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" /> <Button android:id="@+id/bn_click" android:layout_width="match_parent" android:text="点我" android:layout_height="wrap_content" /></android.support.constraint.ConstraintLayout>
然后在Activity里面Import一个包(应该是包),activity_main是文件名
import kotlinx.android.synthetic.main.activity_main.*
不加这行代码控件是无法在Activity直接使用的,如下图,一如既往直接提示
控件的简单使用
TextView:赋值有两种方式:可以用属性,也可以用方法。不过编译器推荐使用属性的方式,如下图
Button绑定事件监听器:不废话如下图
是不是方便了好多,没有了findViewById,也不用去定义控件变量
Kotlin中文站
阅读全文
0 0
- hello Kotlin
- hello Kotlin
- Hello Kotlin
- Hello Kotlin
- Hello Kotlin
- Hello Kotlin
- Hello Kotlin
- Hello Kotlin
- 写出Kotlin版Hello!kotlin
- Hello World With Kotlin
- Kotlin的hello world
- kotlin hello world
- Kotlin say Hello Android
- Hello Kotlin第一篇
- Hello World Kotlin
- Kotlin学习(二)Hello Kotlin
- HelloKotlin(kotlin配置环境变量,kotlin hello world,kotlin 入门)
- Kotlin 学习(1) -- Hello World
- 蚁群算法代码实现
- Android开发中SQLite Expert的操作技巧
- 吝啬的国度
- 12、vue.js 之ref
- Android AOP三大金刚简介
- Hello Kotlin
- JAVA面试要点002_Git中fetch和pull的区别
- IOS技术支持
- 自勉一
- Shell脚本基础19-for循环
- 为LPC1549 LPCXpresso评估板开发基于mbed的项目
- Lua知识点一
- 设计模式学习笔记——单例模式
- 数据结构与算法(27)——排序(二)