zoukankan      html  css  js  c++  java
  • 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");
        }
    
    }
  • 相关阅读:
    个人开发框架总结(六)
    使用Forms身份验证
    接口IStateManager的使用心得
    Remoting中向服务器传送新对象时应注意的问题
    具有反色文本的进度条绘制方法
    中文姓名的VbScript验证方法
    个人开发框架总结(七)
    Asp.net MVC 实例
    直接对List对象排序,提高系统性能
    Spring 简单实现邮件发送
  • 原文地址:https://www.cnblogs.com/hbuwyg/p/7806341.html
Copyright © 2011-2022 走看看