• Android Studio 3.0 | Kotlin 测试


    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");
        }
    
    }
  • 相关阅读:
    Python之struct模块浅谈
    看头发知健康
    ZeroMQ:云计算时代最好的通讯库
    粗盐热敷疗法经验汇总
    百度2011校招笔试算法题一
    new/delete 和malloc/free 的区别一般汇总
    Trie字典树
    百度2012校招笔试题之全排列与组合
    百度2011校招笔试算法题二
    执行程序的内存分布总结
  • 原文地址:https://www.cnblogs.com/hbuwyg/p/7806341.html
Copyright © 2020-2023  润新知