亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android PopupWindow 點(diǎn)擊外面取消實(shí)現(xiàn)代碼

 更新時(shí)間:2015年04月24日 11:54:30   投稿:junjie  
這篇文章主要介紹了Android PopupWindow 點(diǎn)擊外面取消實(shí)現(xiàn)代碼,本文直接給出核心實(shí)現(xiàn)代碼,代碼中包含注釋,需要的朋友可以參考下
private void showPopupView()
  {
    if (mPopupWindow == null)
    {
      View view = getLayoutInflater().inflate(R.layout.newest_layout, null);
      mPopupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      mPopupWindow.setFocusable(true);//需要設(shè)置為ture,表示可以聚焦

        //需要設(shè)置背景,用物理鍵返回的時(shí)候
			        mPopupWindow.setBackgroundDrawable(new BitmapDrawable(getResources()));
			        mPopupWindow.setOutsideTouchable(true);

      view.setOnTouchListener(new OnTouchListener()// 需要設(shè)置,點(diǎn)擊之后取消popupview,即使點(diǎn)擊外面,也可以捕獲事件
      {
        public boolean onTouch(View v, MotionEvent event)
        {
          if (mPopupWindow.isShowing())
          {
            Trace.Log("-------------------onTouch------------");
            mPopupWindow.dismiss();
          }
          return false;
        }
      });

    }

    if (mPopupWindow.isShowing())
    {
      mPopupWindow.dismiss();
    }
    else
    {
      View parent = findViewById(R.id.newest);
      mPopupWindow.showAsDropDown(parent);// 顯示再指定控件的下面
    }

  }

相關(guān)文章

最新評(píng)論