Google's official support, experience.
Xml
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns: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" > <TextViewAndroid:id= "@+id/textview"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Hello world!" /> <ButtonAndroid:id= "@+id/button"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Change text in TextView"Android:onclick= "Button_onclick"/> <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Test Toast function" /></LinearLayout>
Kt
PackageCom.example.kotlindemoImportandroid.support.v7.app.AppCompatActivityImportAndroid.os.BundleImportAndroid.view.ViewImportAndroid.widget.ToastImportkotlinx.android.synthetic.main.activity_main.*classmainactivity:appcompatactivity () {Override fun OnCreate (Savedinstancestate:bundle?) { Super. OnCreate (savedinstancestate) Setcontentview (r.layout.activity_main) Button2.setonclicklistener (View.OnC Licklistener {Toast.maketext ( This, "Test Toast", Toast.length_short). Show ()})} Fun Button_onclick (View:view) {Textview.settext ("Test Change"); }}
Android Studio 3.0 | Kotlin Test