关闭

自定义按钮 点击弹出PopupWindow窗口

3110人阅读 评论(0) 收藏 举报

        我记得这个好像是看得不记得是那个软件的写法是这样的,自己整理了下。

       大致的意思就是点击按钮,弹出一个预先准备好的PopupWindow窗口。

接口:

public abstract interface MyPopup
{
  public abstract void popAwindow(View paramView);
}

 

自定义按钮:

public class PopuMenuTextButton extends Button
{
  private MyPopup pwindow;

  public PopuMenuTextButton(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
  }

  protected void onDetachedFromWindow()
  {
    if (this.pwindow != null)
      this.pwindow.popAwindow(this);
    super.onDetachedFromWindow();
  }

  public void setOnDetachedListener(MyPopup paramnl)
  {
    this.pwindow = paramnl;
  }
}

 

使用:

    private PopuMenuTextButton pbtn;
    
    private PopupWindow pwindow;

    /**
     * 显示PopupWindow 窗口 <功能详细描述>
     */
    public void showPop()
    {
        int i1 = -1;
        if (upOrdown() == i1)
        {
            View localView1 = LayoutInflater.from(this).inflate(R.layout.layout_popup_calllog, null);
            View localView2 = localView1.findViewById(R.id.popup_callLog_all);
            View localView3 = localView1.findViewById(R.id.popup_callLog_miss);
            View localView4 = localView1.findViewById(R.id.popup_callLog_incoming);
            View localView5 = localView1.findViewById(R.id.popup_callLog_outgoing);
            localView2.setOnClickListener(this);
            localView3.setOnClickListener(this);
            localView4.setOnClickListener(this);
            localView5.setOnClickListener(this);
            PopupWindow localPopupWindow1 = new PopupWindow(localView1, i1, i1);
            this.pwindow = localPopupWindow1;
            this.pwindow.showAsDropDown(this.pbtn);
        }
    }
    
    @Override
    public void popAwindow(View paramView)
    {   //需要继承MyPopup接口
        upOrdown();
    }

 



 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场