android开发-PopupWindow

//加载一个布局

View root=MainActivity.this.getLayoutInflater().inflate(R.layout.activity_main, null);
//创建一个 PopupWindow 实例 

 final PopupWindow popup=new PopupWindow(root, 300, 300);

//在弹出窗口外面点击 取消窗口 必须设置一下这两个

          popup.setBackgroundDrawable(new ColorDrawable(this.getResources().getColor     (android.R.color.background_dark)));
        popup.setOutsideTouchable(true);

 

//事件
        bt.setOnClickListener(new OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    popup.showAsDropDown(arg0);
   }
  });
       

你可能感兴趣的:(android开发-PopupWindow)