Kotlin环境搭建

作者: 奔跑吧技术人 | 来源:发表于2019-01-11 22:08 被阅读35次

效果展示

方式一 直接新建新项目

AS3.1已经自带Kotlin插件,不需要额外安装

方式二 module中添加kotlin支持

project build.gradle

buildscript {
    ext.kotlin_version = '1.3.11'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

module build.gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
}

dependencies {
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

Activity

class TestActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        tvshow.text = "hello-kotlin"
    }
}

Activity-xml

<?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=".MainActivity">

    <TextView
        android:id="@+id/tvshow"
        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>

Kotlin重构系列分享教程

Kotlin环境搭建
Kotlin重构初体验之告别FindViewById
Kotlin重构如何兼容原先的ButterKnife、EventBus3.1

请关注我(分享日常开发)

相关文章

  • Kotlin 学习笔记

    目录 Hello Kotlin 搭建 Kotlin 学习环境(SpringBoot 版)解读 hello-kotl...

  • Kotlin 学习第二弹 类,函数,字段

    上篇我们介绍了Kotlin环境搭建,这篇,我们来愉快的编写Kotlin代码吧! Kotlin学习第一弹,搭建kot...

  • 用vscode写kotlin是啥感觉

    kotlin 官网提供了如下方式搭建kotlin环境: Getting Started with IntelliJ...

  • Kotlin Android Extensions

    在一篇的Kotlin for Android的环境搭建中,已经简单介绍了怎么在AS中配置Kotlin的开发环境,其...

  • Kotlin环境搭建

    创建Android工程 安装Kotlin插件 File -> Setting -> Plugins 输入Kotli...

  • 搭建Kotlin环境

    下载 https://kotlinlang.org/ IntelliJ IDEA和Android Studio可以...

  • Kotlin环境搭建

    效果展示 方式一 直接新建新项目 AS3.1已经自带Kotlin插件,不需要额外安装 方式二 module中添...

  • Kotlin for Android

    Kotlin Android 环境搭建打开 Settings ( Mac 为 Preferences) 面板,在右...

  • (三)Hello Kotlin

    Kotlin学习合集上一篇文章:(二)搭建Kotlin开发环境 1 点击Create New Project 创建...

  • 5.1 三分钟开启第一个 Kotlin 工程

    写在前面:Kotlin介绍 1、Kotlin是什么? 在正式搭建环境之前,我想有必要先和大家介绍下Kotlin,以...

网友评论

    本文标题:Kotlin环境搭建

    本文链接:https://www.haomeiwen.com/subject/juufdqtx.html