是否可以在Android中为Toast提供点击监听器?

时间:2014-08-09 10:14:06

标签: android onclicklistener toast custom-view

我正在尝试提供点击监听器toast message.Any一个告诉我是否有可能在Android中为Toast提供点击监听器?

我正在使用自定义视图进行吐司,我将onclick监听器应用到我的视图中它无法正常工作。我对此进行了调整

LayoutInflater inflater = (LayoutInflater) ConnectToXMPP.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View layout = inflater.inflate(R.layout.chat_message_alert_dialog,null);
TextView text = (TextView) layout.findViewById(R.id.chat_popup_message_textview);
text.setText("From : " + fromName+ "\n" + fromName);
LinearLayout chatMessageLayout = (LinearLayout)    
layout.findViewById(R.id.chat_popup_message_layout);

Toast toast = new Toast(ConnectToXMPP.mContext);
toast.setView(layout);
toast.setGravity(Gravity.CENTER_VERTICAL, 0,0);
toast.setDuration(60000);
toast.getView().setClickable(true);
toast.getView().setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

     Toast.makeText(ConnectToXMPP.mContext,"toast touched",Toast.LENGTH_SHORT).show();

}
});
toast.show();

2 个答案:

答案 0 :(得分:0)

Janusz's回答

无法点击敬酒。无法在Toast消息中捕获单击。您需要为此构建一个对话框。查看Creating Dialogs了解更多信息。

Toast类上的API声明toast永远不会获得焦点,因为toast不是视图,所以没有onClick消息。我认为因此也不能点击Toast的孩子。

答案 1 :(得分:0)

看看John Persanos SuperToast库。它包括可点击的祝酒词。 Github repo

相关问题