且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我只需要覆盖的吐司类节目()

更新时间:2023-02-21 11:54:51

你叫 super.show()您的覆盖范围内?这可能是因为 Toast.show()呼吁这一点,你的覆盖现正就那么呼叫不会发生。

Did you call super.show() within your override? It's likely that Toast.show() is calling this, and your override is now making it so that the call doesn't happen.

什么你可能需要做的是这样的:

What you'll probably need to do is something like this:

public class MyOwnToast extends Toast {
    public MyOwnToast(Toast toast) {
        //Code to initialize your toast from the argument toast

        //Probably something like this:
        this.setView(toast.getView());
        this.setDuration(toast.getDuration());
        //etc. for other get/set pairs in Toast
    }

    public static MyMakeText(Context context, CharSequence text, int duration) {
        return new MyOwnToast(Toast.makeText(context, text, duration));
    }

    public void show() {
        //Your show override code, including super.show()
    }
}

然后,当你想使用它,这样做:

Then, when you want to use it, do:

MyOwnToast.MyMakeText(activity, "Some text", Toast.LENGTH_LONG).show();

填写本表格时,请参阅敬酒文档作为参考:的http:// developer.android.com/reference/android/widget/Toast.html