Sponsor

Android Tutorial on Button Click Event And Toast Message with SoftwareTechIT | Example of Button Click & Event Toast Massage Android Studio Tutorial


#2 Theory of Button Click Event & Toast Massage| Android Studio Tutorial |#SoftwareTechIT


MainActivity.java

package com.example.buttontoastdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
   Button btclick;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btclick=(Button)findViewById(R.id.button);

        btclick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // Toast create

                Toast.makeText(MainActivity.this, "Welcome To Button Toast Example", Toast.LENGTH_SHORT).show();

            }
        });


    }
}

#3 Example of Button Click & Event Toast Massage Android Studio Tutorial SoftwareTechIT




activity_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">


    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="136dp"
        android:layout_marginLeft="136dp"
        android:layout_marginTop="304dp"
        android:text="Button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>



Post a Comment

0 Comments