发行驳回弹出窗口 [英] Issue dismissing popup window

查看:144
本文介绍了发行驳回弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个弹出式菜单,它显示了在点击一个按钮。这是我的onclick方法。

I have a popup menu implemented , which shows up on click of a button. This is my onclick method.

public void showOverflow(View view) {

    boolean click = true;
    Button action = (Button) findViewById(R.id.btbAction);

    LayoutInflater inflater = (LayoutInflater) main.this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View popupView = inflater.inflate(R.layout.overflow_layout, null);
    final PopupWindow pw = new PopupWindow(popupView,
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    pw.setOutsideTouchable(true);
    if (click) {
        pw.showAsDropDown(action, 0, 0);
        click = false;
    } else {
        pw.dismiss();
        click = true;
    }
}

在弹出窗口显示了单击按钮时。现在的问题是,当我触摸弹出窗口外的窗口没有被驳回。 我想这属性设置为弹出式窗口

The popup window shows up when the button is clicked. Now, the problem is that the window is not dismissed when i touch outside the popup window. I tried setting this property to the popup window

pw.setOutsideTouchable(true);

观光保持不变。请帮我解决这个问题。

Things remain the same. Please help me fix this

推荐答案

您应该 setOutsideTouchable 调用的参数更改为 pw.setOutsideTouchable(假);

You should change the setOutsideTouchable call's parameter to true: pw.setOutsideTouchable(false);

控制是否弹出将外通知的触摸事件   它的窗口。这仅是有道理的弹出窗口是可触   但不可作为焦点,这意味着窗口外接触将是   输送到后面的窗口。默认值是

Controls whether the pop-up will be informed of touch events outside of its window. This only makes sense for pop-ups that are touchable but not focusable, which means touches outside of the window will be delivered to the window behind. The default is false.

如果弹出显示时,调用此方法将生效只   下次弹出窗口显示或通过向的一个手动呼叫   更新()方法。

If the popup is showing, calling this method will take effect only the next time the popup is shown or through a manual call to one of the update() methods.

参数:触摸 真正如果弹出应该接受外界接触   事件的错误,否则

Parameters: touchable true if the popup should receive outside touch events, false otherwise

在另一方面,什么是点击局部变量该怎么办?它被设置为真的,所以它总是会强制执行 PW 弹出,每当 showOverflow 方法被调用,并没有任何理由将其设置为错误后,因为它的生命周期结束时你离开的方法。

On the other hand, what is the click local variable supposed to do? It is set to true, so it will always force the pw to pop up, whenever the showOverflow method is called, and for no reason it is set to false later, because it's life cycle ends as you leave that method.

您code应该是这个样子:

Your code should look something like this:

private LayoutInflater inflater;
private Button action;
private PopupWindow pw;
private View popupView;
/*
 * (non-Javadoc)
 * @see android.app.Activity#onCreate(android.os.Bundle)
 */
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    popupView = inflater.inflate(R.layout.overflow_layout, null, false);

    action = (Button) findViewById(R.id.action);
    action.setOnClickListener(this);
}

public void showOverflow()
{
    pw = new PopupWindow(getApplicationContext());
    pw.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
    pw.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    pw.setOutsideTouchable(true);

    pw.setContentView(popupView);
    pw.showAsDropDown(action, 0, 0);
}

getApplicationContext() 768,16如果你是一个活动类中使用。否则,你应该得到的上下文作为一个参数。

The getApplicationContext() shoud be used in case you are inside an Activity class. Otherwise you should get the Context as a parameter.

这篇关于发行驳回弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆