如果我以正确的方式理解,
// 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));
});
我已经检查这个显示弹出式菜单。它工作正常。
yes我的代码很相似,但'setOutsideTouchable(true)'不适用于onClick 'isShowing()'每次都是false,因为在触发onClick之前关闭弹出框。 – Rumen
你想做什么做什么呢?当用户在外面接触时,你想关闭弹出窗口? –
是的,我想外面关闭时,触摸也有触发锚。像[这](http://searchengineland.com/figz/wp-content/seloads/2012/02/google-mobile-navigation-ui-test-feb2012-2.png),当你点击锚关闭并打开窗户,但也可以在外面触摸时关闭。 – Rumen