【问题标题】:can't change duration in Custom Toast [duplicate]无法更改自定义 Toast 中的持续时间 [重复]
【发布时间】:2015-05-06 10:25:41
【问题描述】:

我有一个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); 不起作用 有谁知道我的代码有什么问题或者我该如何以另一种方式做到这一点?

【问题讨论】:

标签: android duration android-toast


【解决方案1】:

你不能那样做。如您所知,吐司只有两种变体

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

反正 cmets 中的链接指向正确的答案,后来注意到了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多