Is it possible to programmatically add an image to a toast popup?
class CustomToast extends AppCompatActivity {
Button custom_toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_toast);
custom_toast = (Button) findViewById(R.id.customToast);
custom_toast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater=getLayoutInflater();
View layout=inflater.inflate(R.layout.custom_toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root));
TextView toastTextView=(TextView) findViewById(R.id.toastTextView);
ImageView toastimageview=(ImageView) findViewById(R.id.toastImageView);
toastTextView.setText("Custom toast in android");
toastimageview.setImageResource(R.drawable.ic_launcher_background);
Toast toast=new Toast(CustomToast.this);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
});
}
}