Kotlin在Android开发中的环境配置
来源:互联网 发布:seo关键词优化技巧 编辑:程序博客网 时间:2024/06/12 22:36
在Android Studio上面进行安装插件
在Settings ->Plugins ->Browse repositores.. ->kotlin 安装完成后重启Android Studio就生效了 如图所示:
在Android Studio中做Kotlin相关配置
(1)在根目录 的build.gradle中进行配置使用,代码如下:
buildscript { ext.kotlin_version = '1.1.2-4' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }}allprojects { repositories { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}
(2)在app/build.gradle 中配置的使用
apply plugin: 'kotlin-android'apply plugin: 'kotlin-android-extensions'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
repositories { mavenCentral()}
这样,kotlin的配置就已经完成了,我们来写第一个项目hello world
开始进行第一个小Demo的使用
(1)在布局文件中写一个textview控件,代码如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout 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" android:orientation="vertical" tools:context="com.yoyoyt.kotlindemo.ThreeActivity"> <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="aaaa"/></LinearLayout>
(2)我们进行找id赋值使用
第一种找控件的方式 代码如下:
import android.os.Bundleimport android.support.v7.app.AppCompatActivityimport android.widget.TextViewimport kotlinx.android.synthetic.main.activity_three.*class ThreeActivity : AppCompatActivity() { private var b : TextView ?= null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_three) text.text="aaa" }}
第二找控件的方法 代码如下:
import android.os.Bundleimport android.support.v7.app.AppCompatActivityimport android.widget.TextViewimport android.widget.Toastclass ThreeActivity : AppCompatActivity() { private var b : TextView ?= null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_three) b = findViewById(R.id.text) as TextView b!!.text="shds" Toast.makeText(this,b!!.text.toString(),Toast.LENGTH_SHORT).show() }}
这样,我们的一个简单的demo就已经实现了,效果图我就不贴了。
阅读全文
0 0
- Kotlin在Android开发中的环境配置
- Android Studio 配置Kotlin 开发环境
- Android Studio配置Kotlin开发环境
- Android Studio配置Kotlin开发环境笔记
- Android Studio Kotlin 开发环境配置
- Android Studio Kotlin 开发环境配置
- Android studio 配置Kotlin的开发环境
- android studio 配置kotlin开发环境
- Kotlin(一)-->Android Studio配置Kotlin开发环境
- Kotlin(一)-->Android Studio配置Kotlin开发环境
- Kotlin(一)-->Android Studio配置Kotlin开发环境
- Kotlin配置开发Android
- Android开发Kotlin配置
- android+Kotlin开发之Android Studio的环境配置
- Android 开发中的KotLin
- Kotlin开发环境的配置
- Android急速开发--kotlin环境配置和遇到的问题
- Android Studio配置Kotlin开发环境的最简单方式
- PE结构->【导出表】Export
- java.sql.SQLException: Unable to run insert stmt on object 解决办法
- 移动游戏的交互和较量
- 根据map中的key或者value值进行排序
- 实现对properties文件的有序读写
- Kotlin在Android开发中的环境配置
- jsp页面Datetime类型获取年月日。
- 数组—添加删除方法
- Logstash简单介绍
- Thread.join()的用法
- Unity Learning for Day 21
- java文件上传和下载
- 获得逻辑能力——用数组制作记事本(二)
- Codeforces Xenia and Ringroad