2014-12-27 400 views
0

我在Android中弹出窗口时遇到了一些问题。我想要做的是当用户第一次点击按钮时,弹出窗口会显示。如果弹出窗口显示并且用户再次点击该按钮,弹出窗口将被隐藏。下面是我的XML的弹出窗口:Android弹出窗口在弹出窗口外弹出时解雇

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/llAttendeeList" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="#000000" 
> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="HELLO" /> 

</LinearLayout> 

与行为守则,其中上点击按钮,就会执行这个方法:

private void openPopUp(){ 
    LayoutInflater layoutInflater = (LayoutInflater) getActivity() 
      .getBaseContext().getSystemService(
        context.LAYOUT_INFLATER_SERVICE); 
    View popupView = layoutInflater.inflate(
      R.layout.event_attendee_pop, null); 
    llAttendeeList = (LinearLayout) popupView 
      .findViewById(R.id.llAttendeeList); 
    final PopupWindow popupWindow = new PopupWindow(popupView, 
      LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
    popupWindow.setOutsideTouchable(true); 

    popupWindow.setTouchInterceptor(new OnTouchListener() { 
       public boolean onTouch(View v, MotionEvent event) { 
        if (event.getAction() == MotionEvent.ACTION_OUTSIDE) 
        { 
         popupWindow.dismiss(); 
         return true; 
        } 
        return false; 
       } 
      }); 
    popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0); 
} 

但是,当用户单击这个按钮,在弹出的做出现了。但是当我在弹出窗口外单击时,它不会消失。有任何想法吗?

在此先感谢。

回答

-2

添加popupWindow.setContentView(popupView),然后再试一次

+0

你有什么想法如何设置弹出的正下方有操作栏marginTop? –

+0

有什么想法?我无法将其设置到我想要的位置 –

1

我想通了,我已经设置这个弹出窗口:

popupWindow.setOutsideTouchable(true); 
    popupWindow.setBackgroundDrawable(new ColorDrawable());