我正在android中实现一个弹出窗口。当我在弹出窗口外单击时,我可以忽略它,但是当我点击同一个imageview /按钮时我想要忽略它。
1.on click on button1 it opens pop up
2.If I click outside it closes pop up
3.If I click on button1(when pop up is open), it closes pop and reopens it again
我想要的是什么 如果我点击button1(当弹出窗口打开时),它只会关闭pop并且不会重新打开,除非第二次点击。
这可能吗?
注意:我不想在弹出窗口中有一个关闭按钮。
pop_one.setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
pop_one.getLocationOnScreen(location);
p = new Point();
p.x = location[0];
p.y = location[1];
popupshow(one_one_text,pop_one);
}
});
方法是:
public void popupshow(String pop_text, ImageView pop_one) {
int width = display.getWidth(); // deprecated
System.out.println("jsfjsfjnsdf"+width);
int new_width = width-(width/6) ;
LayoutInflater layoutInflater = (LayoutInflater) getActivity()
.getBaseContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(
R.layout.career_options_popup_short, null);
final PopupWindow popupWindow = new PopupWindow(popupView, new_width,
LayoutParams.WRAP_CONTENT);
TextView popup_text = (TextView) popupView
.findViewById(R.id.popup_text);
popup_text.setMinimumWidth(300);
popup_text.setText(pop_text);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(popupView,p.x/10, p.y +p.x/8);
System.out.println("value of x" + p.x+" "+p.y);
//System.out.println("value of new width " + new_width+" get width "+popupWindow.getWidth()+" text box width "+popup_text.getWidth()+"pop view"+popupView.getWidth());
popupWindow.setFocusable(true);
}
此致 ASMI
答案 0 :(得分:2)
我认为这将解决您的问题,请点击按钮
popupWindow.dismiss();
答案 1 :(得分:0)
您需要设置弹出窗口的属性setOutsideTouchable(false)
答案 2 :(得分:-1)
您需要的是boolean
isShowing将此boolean
设置为在函数popupshow
public void popupshow(String pop_text, ImageView pop_one) {
isShowing=true;
int width = display.getWidth(); // deprecated
System.out.println("jsfjsfjnsdf"+width);
int new_width = width-(width/6) ;
LayoutInflater layoutInflater = (LayoutInflater) getActivity()
.getBaseContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(
R.layout.career_options_popup_short, null);
final PopupWindow popupWindow = new PopupWindow(popupView, new_width,
LayoutParams.WRAP_CONTENT);
TextView popup_text = (TextView) popupView
.findViewById(R.id.popup_text);
popup_text.setMinimumWidth(300);
popup_text.setText(pop_text);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(popupView,p.x/10, p.y +p.x/8);
System.out.println("value of x" + p.x+" "+p.y);
//System.out.println("value of new width " + new_width+" get width "+popupWindow.getWidth()+" text box width "+popup_text.getWidth()+"pop view"+popupView.getWidth());
popupWindow.setFocusable(true);
}
现在当您点击button1
时,只需检查此boolean
pop_one.setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
if(isShowing)
{
popupWindow.dismiss();
isShowing=false;
}
else
{
pop_one.getLocationOnScreen(location);
p = new Point();
p.x = location[0];
p.y = location[1];
popupshow(one_one_text,pop_one);
}
}
});