无法更改自定义Toast中的持续时间

时间:2015-03-05 06:20:32

标签: android duration android-toast

我有一个Custom Toast我想让它显示10秒

这是我的代码:

                        LayoutInflater inflater = getLayoutInflater();
                        View layout = inflater.inflate(R.layout.custom_toast,
                                (ViewGroup) findViewById(R.id.toast_layout_root));

                        TextView text = (TextView) layout.findViewById(R.id.text);
                        text.setText("please wait.... ");
                        text.setTypeface(type);

                        Toast toast = new Toast(getApplicationContext());
                        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                        toast.setDuration(10000);
                        toast.setView(layout);
                        toast.show();

但是通过设置toast.setDuration(10000);它并不起作用 有谁知道我的代码有什么问题或者我怎么能以另一种方式做到这一点?

1 个答案:

答案 0 :(得分:0)

你做不到。 Toast只有两种变体,你已经知道了

private static final int LONG_DELAY = 3500; // 3.5 seconds
private static final int SHORT_DELAY = 2000; // 2 seconds

无论如何,评论中的链接指向正确答案,后来注意到