![Please check this out.](https://i.stack.imgur.com/dmaS9.png)
如果我以正確的方式理解,
// 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