package com.example.toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button byDefaultToast,simpleToast,nestedToast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
byDefaultToast = findViewById(R.id.byDefault);
simpleToast = findViewById(R.id.simpleToast);
nestedToast = findViewById(R.id.nestedToast);
// By Default Toast
byDefaultToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "By Default Toast", Toast.LENGTH_LONG).show();
}
});
// Simple Toast
simpleToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast toast = Toast.makeText(MainActivity.this,"Simple Toast",Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0,0);
toast.show();
}
});
// Nested Toast
nestedToast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast toast = Toast.makeText(MainActivity.this,"Nested Toast",Toast.LENGTH_LONG);
toast.setGravity(Gravity.BOTTOM | Gravity.RIGHT, 0,0);
toast.show();
}
});
}
}
0 Comments