Android PopupWindow 防止锚点点击关闭

问题描述 投票:0回答:1

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

已修复!!!

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

popupWindow.setFocusable(true);

修复它。

android toggle popupwindow dismiss
1个回答
0
投票

Please check this out.

如果我理解正确的话,

// 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));

            });

我已经检查过了。运行良好。

© www.soinside.com 2019 - 2024. All rights reserved.