Adding image to Toast?

2019-01-10 03:46发布

Is it possible to programmatically add an image to a toast popup?

7条回答
Emotional °昔
2楼-- · 2019-01-10 04:26

You can create any view programmatically (since I am assuming you are asking on how to do this WITHOUT using a LayoutInflater) and call setView on the Toast you made.

    //Create a view here
    LinearLayout v = new LinearLayout(this);
    //populate layout with your image and text or whatever you want to put in here

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(v);
    toast.show();
查看更多
登录 后发表回答