我有一个 PopupWindow,里面有两个按钮。它们按预期工作,当按下并按住时会进入按下状态并执行操作。当我快速按下按钮并松开时,问题就出现了。这会导致按钮以及 PopupWindow 上的背景变得透明。仅当用户单击而不是按住时才会发生这种情况。有什么想法可能会导致这种情况吗?
显示弹出窗口的代码:
final String path = argpath;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.productpopup, null, false);
ImageView iv = (ImageView) layout.findViewById(R.id.big_product_image);
TextView tv = (TextView)layout.findViewById(R.id.productDescription);
if (fullDescription.equals(""))
tv.setVisibility(View.GONE);
else
tv.setText(fullDescription);
if (iv != null && imageID != ImageManager.NOIMAGE) {
iv.setImageResource(imageID);
popup = new PopupWindow(layout,
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT,
true);
BitmapDrawable bm = new BitmapDrawable();
popup.setBackgroundDrawable(bm);
popup.setOutsideTouchable(true);
popup.setAnimationStyle(android.R.style.Animation_Toast);
popup.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0);
Button closeButton = (Button) layout.findViewById(R.id.close);
Button orderButton = (Button) layout.findViewById(R.id.order);
closeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
popup.dismiss();
}
});
if (!path.equals("")) {
orderButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (path != null)
startActivity(routeTo(path));
popup.dismiss();
}
});
}
}
最佳答案
好吧,问题是这两行:
BitmapDrawable bm = new BitmapDrawable();
popup.setBackgroundDrawable(bm);
不确定为什么会导致这种情况发生,但取出后它会按预期工作。
关于java - 快速单击时 PopupWindow 中的按钮会变成透明吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8977197/