gpt4 book ai didi

android - popupWindow.setOnDismissListener 再次触发popupmenu

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:03:10 26 4
gpt4 key购买 nike

下面是我的代码,菜单 - ImageView菜单底部 - ImageView我的要求是在显示弹出窗口时显示 menubottom 图像。

menu.setOnClickListener(new OnClickListener() 
{
public void onClick(View v)
{View layout=(View)getLayoutInflater().inflate(R.layout.navigationbar, null);
popupWindow = new PopupWindow(getApplicationContext());
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setContentView(layout);
popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(swidth);
popupWindow.setFocusable(false);
popupWindow.setOutsideTouchable(true);
popupWindow.setAnimationStyle(-1);

if(x==1)
{ popupWindow.showAsDropDown(menubottom);
menubottom.setVisibility(View.VISIBLE);
x=0;
}
else
{
popupWindow.dismiss();
popupWindow=null;
}
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

@Override
public void onDismiss() {
// TODO Auto-generated method stub
menubottom.setVisibility(View.INVISIBLE);
x=1;

}
});

}

}

问题:单击菜单按钮时,将显示弹出窗口并显示 menubottom。再次按下菜单时,弹出菜单会隐藏然后再次显示。

在弹出菜单外按下时,它按预期工作(隐藏弹出菜单和菜单底部)

我认为,setOnDismissListener 会再次触发 menu.setOnClickListener。提前致谢。

最佳答案

我认为问题出在弹出之后,因为菜单按钮在 popupwindow 之外,popupwindow 被关闭并且菜单按钮的 onclick 再次触发。所以也许你可以做这样的事情(最初是x=1)

menu.setOnClickListener(new OnClickListener() 
{
public void onClick(View v)
{View layout=(View)getLayoutInflater().inflate(R.layout.navigationbar, null);
popupWindow = new PopupWindow(getApplicationContext());
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setContentView(layout);
popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(swidth);
popupWindow.setFocusable(false);
popupWindow.setOutsideTouchable(true);
popupWindow.setAnimationStyle(-1);

/* if(x==1)
{ popupWindow.showAsDropDown(menubottom);
menubottom.setVisibility(View.VISIBLE);
x=0;
}
else
{
popupWindow.dismiss();
popupWindow=null;
} */

if(x==0) {
x=1;
} else {
popupWindow.showAsDropDown(menubottom);
menubottom.setVisibility(View.VISIBLE);

}
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

@Override
public void onDismiss() {
// TODO Auto-generated method stub
menubottom.setVisibility(View.INVISIBLE);
x=0;

}
});

}

关于android - popupWindow.setOnDismissListener 再次触发popupmenu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30128020/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com