本篇文章給大家分享的是有關Android中配置一個Kotlin開放環(huán)境,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

創(chuàng)新互聯(lián)是一家專業(yè)從事成都網(wǎng)站建設、做網(wǎng)站的網(wǎng)絡公司。作為專業(yè)網(wǎng)站制作公司,創(chuàng)新互聯(lián)依托的技術(shù)實力、以及多年的網(wǎng)站運營經(jīng)驗,為您提供專業(yè)的成都網(wǎng)站建設、全網(wǎng)營銷推廣及網(wǎng)站設計開發(fā)服務!
(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的配置就已經(jīng)完成了,我們來寫第一個項目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.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import 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.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import android.widget.Toast
class 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()
}
}以上就是Android中配置一個Kotlin開放環(huán)境,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學到更多知識。更多詳情敬請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章題目:Android中配置一個Kotlin開放環(huán)境
網(wǎng)頁URL:http://chinadenli.net/article18/gesdgp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、外貿(mào)建站、手機網(wǎng)站建設、商城網(wǎng)站、做網(wǎng)站、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)