4

我有一个 popupWindow,它在按钮单击时显示 AsDropDown,并且此 popupWindow 具有 setOutsideTouchable(true),我想在单击按钮时切换显示弹出窗口,但在单击弹出窗口外部时也关闭。问题是在单击按钮之前调用外部触摸,然后我的弹出窗口是隐藏并显示。有没有办法做到这一点 ?

固定的

我发现问题是我的弹出窗口没有集中,我必须打电话

popupWindow.setFocusable(true);

要解决这个问题。

4

1 回答 1

0

请检查一下。

如果我理解正确,

// Pop up Window showing

    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    popupView = layoutInflater.inflate(R.layout.menu_popup, null);
    popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    popupWindow.setOutsideTouchable(true);

 // Add setBackgroundDrawable to the pop up window to close the dialog :

        popupWindow.setBackgroundDrawable(getResources().getDrawable(
            android.R.color.transparent));
    popupWindow.setTouchable(true);

使用以下检查,您可以根据需要显示弹出窗口

findViewById(R.id.topMenu).setOnClickListener(
            new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                        popupWindow
                                .showAsDropDown(findViewById(R.id.topMenu));

            });

我已经检查过了。它工作正常。

于 2013-10-21T14:10:56.573 回答