Adding image to Toast?

后端 未结 8 1923
梦毁少年i
梦毁少年i 2020-12-02 05:53

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

8条回答
  •  独厮守ぢ
    2020-12-02 06:54

    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();
    

提交回复
热议问题