为自定义Android吐司定义一个事件

时间:2015-01-14 13:04:54

标签: android-toast

我已经制作了一个自定义的Android吐司,并尝试为textview定义单击侦听器事件,但它不起作用....任何帮助?

LayoutInflater inflater = LayoutInflater.from(cntxt);

    View layout = inflater.inflate(R.layout.toast_layout,null);


    TextView text = (TextView) layout.findViewById(R.id.text);

    text.setText(msg);

Toast toast = new Toast(cntxt);

    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);

    text.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method s'tub 
                //didn't go here???
                toast.cancel();
            }
        });

    toast.show();

1 个答案:

答案 0 :(得分:0)

不幸的是,ToastToast的任何子视图都无法接收触摸输入。您必须创建一个模仿View的自定义Toast,并将View附加到布局。