Toast




activity_main.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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/showToast"
        android:layout_width="121dp"
        android:layout_height="68dp"
        android:layout_gravity="center"
        android:background="@color/colorPrimary"
        android:text="Show Toast"
        android:textColor="#fff" />


</LinearLayout>






MainActivity.java


package com.example.toast;

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 show;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        show=findViewById(R.id.showToast);

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

                Toast.makeText(getApplicationContext(),"Welcome TO Android",Toast.LENGTH_SHORT).show();
            }
        });
    }
}

Comments

Popular posts from this blog

Generate Signing Release keystore

🚀 COMPLETE CI/CD FROM SCRATCH

Camera Application