我已经制作了一个自定义的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();
答案 0 :(得分:0)
不幸的是,Toast
和Toast
的任何子视图都无法接收触摸输入。您必须创建一个模仿View
的自定义Toast
,并将View
附加到布局。