【Android】 PopupWindow使用小结

    PopupWindow的很多用法网上比较多,我就不做过多解释了,只说下可能会遇到的问题,以及解决办法:

       1、PopupWindow中的listview无响应

      这个主要是因为show写在了setFocusable前面

      2、点击PopupWindow外面区域,不会自动dismiss

      这个主要可能是没有调用setBackgroundDrawable以及setOutsideTouchable,

      当然了,你肯定还得写响应监听这个动作,如下面代码


[java] view plaincopy
 
  1. <span style="font-family: 'Microsoft YaHei'; "><span style="font-size:18px;">     mPopupWindow.setTouchInterceptor(new OnTouchListener() {  
  2.                 @Override  
  3.                 public boolean onTouch(View v, MotionEvent event) {  
  4.                     if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {  
  5.                         mPopupWindow.dismiss();  
  6.                         Log.i("test", "test");  
  7.                         return true;  
  8.                     }  
  9.                       
  10.                     return false;  
  11.                 }  
  12.             });</span></span>  

       3、将默认的箭头放到右边

           

[java] view plaincopy
 
  1. <span style="font-family: 'Microsoft YaHei'; "><span style="font-size:18px;">      int width = getWindowManager().getDefaultDisplay().getWidth();  
  2.       mListView.setIndicatorBounds(width-40, width-10);</span></span>  

 
 
原文地址:https://www.cnblogs.com/xgjblog/p/4152812.html