在我的父級活動我有一個按鈕,當我點擊它顯示PopUpWindow與2 ImageButton ..當此PopUpWindow存在'米無法點擊我的父活動按鈕..這裏是我的代碼,有沒有任何問題..無法點擊父活動按鈕時PopupWindow顯示
public class PopUpExample extends Activity {
Button but;
LinearLayout mainLayout;
PopupWindow popUp;
boolean click = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainLayout = (LinearLayout) findViewById(R.id.main_layout);
but = (Button) findViewById(R.id.main_btn);
but.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
View popView;
if(click){
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
popUp = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false),100, 50, true);
popUp.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
popUp.update();
click = false;
popView = popUp.getContentView();
ImageButton call = (ImageButton) popView.findViewById(R.id.call_btn);
call.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(PopUpExample.this, "Calling...", Toast.LENGTH_SHORT).show();
}
});
ImageButton sms = (ImageButton) popView.findViewById(R.id.sms_btn);
sms.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(PopUpExample.this, "Sms...", Toast.LENGTH_SHORT).show();
}
});
}else{
popUp.dismiss();
click = true;
}
}
});
}
}
只需使用popupWindow.setFocusable(false); ,popwindow解僱和背景視圖點擊將同時工作。 –