码迷,mamicode.com
首页 > 移动开发 > 详细

Android Studio 3.0 | Kotlin 测试

时间:2017-11-08 22:19:51      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:alt   src   cli   linx   button   import   lin   view   width   

Google官方支持了,体验一下。 

技术分享

XML

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
    />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="change text in textview"
        android:onClick="Button_onClick"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test Toast function" />

</LinearLayout>

kt

package com.example.kotlindemo

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        button2.setOnClickListener(View.OnClickListener { Toast.makeText(this, "Test Toast", Toast.LENGTH_SHORT).show() })
    }

    fun Button_onClick(view: View){
        textview.setText("Test change");
    }

}

 

Android Studio 3.0 | Kotlin 测试

标签:alt   src   cli   linx   button   import   lin   view   width   

原文地址:http://www.cnblogs.com/hbuwyg/p/7806341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!