本篇文章給大家分享的是有關(guān)Android中配置一個(gè)Kotlin開放環(huán)境,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
創(chuàng)新互聯(lián)是一家專業(yè)從事成都網(wǎng)站建設(shè)、做網(wǎng)站的網(wǎng)絡(luò)公司。作為專業(yè)網(wǎng)站制作公司,創(chuàng)新互聯(lián)依托的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營(yíng)經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、全網(wǎng)營(yíng)銷推廣及網(wǎng)站設(shè)計(jì)開發(fā)服務(wù)!
(1)在根目錄 的build.gradle中進(jìn)行配置使用,代碼如下:
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)完成了,我們來寫第一個(gè)項(xiàng)目hello world
開始進(jìn)行第一個(gè)小Demo的使用
(1)在布局文件中寫一個(gè)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)我們進(jìn)行找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中配置一個(gè)Kotlin開放環(huán)境,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章題目:Android中配置一個(gè)Kotlin開放環(huán)境
網(wǎng)頁URL:http://muchs.cn/article18/gesdgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、外貿(mào)建站、手機(jī)網(wǎng)站建設(shè)、商城網(wǎng)站、做網(wǎng)站、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)