I just need to override show() for the Toast class

后端 未结 2 847
北海茫月
北海茫月 2021-01-23 22:50

I just need to override the show() method for the Toast class. I created a class which extends Toast class, but then I create a toast mess

2条回答
  •  清酒与你
    2021-01-23 23:23

    More easy way :

    public class MyToast extends Toast { 
    public MyToast(Context context){ 
    super(context)
    this.setView(LayoutInflater.from(context).inflate(R.layout.activity_toast,null));
    }
    public void showMe(){
    super.show();
    }
    public static MyToast myMakeText(Context con,String message,int duration) { 
    MyToast mts = new MyToast(con); 
    View view = mts.getView(); 
    TextView messageArea = view.findViewById(R.id.toastTextView);
     messageArea.setText(message);
     mts.setDuration(duration);
    return mts;
    }}
    

    So you will ask :

    MyToast.myMakeText(this,"my message",7000).showMe();
    

提交回复
热议问题