且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

发行驳回弹出窗口

更新时间:2023-11-19 09:01:28

您应该 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.