2014-09-10 73 views
0

我彈出窗口功能有一個小問題。我想在用戶點擊窗口外部時關閉它。我已經閱讀了很多關於stackoverflow的腳本,但是沒有一篇文章對我有幫助。我試過的是,我試圖popupwindow.setBackgroundDrawable(null);這不適合我。Android - 當點擊視圖外部時關閉popUpWindow

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View layout = inflater.inflate(R.layout.popupmenu_layout, (ViewGroup) findViewById(R.id.popuplinearlayout)); 
    pw = new PopupWindow(layout, 300, 300, true); 
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0); 
    pw.setBackgroundDrawable(null); 
    pw.setOutsideTouchable(true); 
    //Todo remove popup window when outside is touched...  

如果你知道一個很好的文章有什麼可以幫助我,我將不勝感激it.It是更多鈔票這個功能是不是在模擬器工作?我只有模擬器現在。的

pw.setBackgroundDrawable(null); 

(是Android 4.4.2)

回答

0

而是做

pw.setBackgroundDrawable(new BitmapDrawable()); 
1

如果馬辛的構造已被棄用,使用

pw.setBackgroundDrawable(new BitmapDrawable(getResources(),"")); 
0

使用pw.setBackgroundDrawable(new BitmapDrawable(getResources(),""));

設置窗口背景transtarent。

pw.getBackground().setAlpha(0);

+0

你嘗試我張貼的答案?接受它,如果它適合你 – 2014-09-12 17:06:14