Last active
December 20, 2021 05:42
-
-
Save lazy-pr0grammer/861546851d1c241242319fba1135d983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main.xml | |
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
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" | |
tools:context=".MainActivity"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="center_horizontal|center_vertical" | |
android:padding="8dp" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent"> | |
<Button | |
android:id="@+id/b1" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="SHOW A TOAST" | |
android:textSize="14sp"/> | |
</LinearLayout> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
MainActivity.kt | |
package com.toast.kotlin //your package name | |
import androidx.appcompat.app.AppCompatActivity | |
import android.widget.Button | |
import android.widget.Toast | |
import android.os.Bundle | |
public class MainActivity : AppCompatActivity() { | |
private lateinit var b1 : Button | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
b1 = findViewById(R.id.b1) as Button | |
b1.setOnClickListener{ | |
Toast.makeText(this,"Hello this is a toast",3000).show() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment