And*_*dev 2 android toast custom-view onclicklistener
我正在尝试为 toast 消息提供点击监听器。有人告诉我是否可以在 android 中为 Toast 提供点击监听器?
我正在使用 toast 的自定义视图,并且我将 onclick 侦听器应用于我的视图,但它不起作用。我 Triade 这个
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();
Run Code Online (Sandbox Code Playgroud)
小智 5
为此目的使用小吃店。
Snackbar.make(findViewById(android.R.id.content), "Hi I'm snack bar", Snackbar.LENGTH_LONG)
.setTextColor(Color.parseColor("#FFFFFF"))
.setDuration(30000)
.setBackgroundTint(Color.parseColor("#716E7C"))
.setActionTextColor(Color.parseColor("#49FF00"))
.setAction("Refresh") {
// Do whatever you want
}.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4646 次 |
| 最近记录: |