Toast.makeText(this, "Hello World!", Toast.LENGTH_SHORT).show();
Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout customToastLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.custom_toast, null); ImageView imageView = customToastLayout.findViewById(R.id.image_view); imageView.setImageResource(R.drawable.ic_check_circle); TextView textView = customToastLayout.findViewById(R.id.text_view); textView.setText("Custom Toast"); toast.setView(customToastLayout); toast.show();This code will create a custom Toast message with an image and customized text. The layout for the Toast is inflated from a custom_toast.xml file. In both examples, the Toast class is imported from the android.widget package. The Toast class provides various methods to customize the message such as setting the duration, gravity, layout, view, etc. It is a convenient way to display notifications to the users without interrupting their workflow.