【问题标题】:define an event for custom android toast为自定义 android toast 定义一个事件
【发布时间】:2015-01-14 13:04:53
【问题描述】:

我制作了一个自定义的 android toast 并尝试为 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();

【问题讨论】:

    标签: android-toast


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多