Я хочу отключить всплывающее окно, щелкнув за пределами всплывающего окна или кнопкой «Назад», но при нажатии на кнопку «Назад» мой выход приложения, вместо выхода из приложения, я хочу закрыть всплывающее окно.откройте всплывающее окно по кнопке «назад»
вот мой код,
ivmainmenu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popupwindow, null);
final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
popupWindow.showAsDropDown(ivmainmenu, 0,14);
popupView.setPadding(0, 0, 0, 10);
popupWindow.showAsDropDown(ivmainmenu);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setOutsideTouchable(false);
TextView tvpopupwork = (TextView)popupView.findViewById(R.id.tvpopupwork);
TextView tvpopupabout = (TextView)popupView.findViewById(R.id.tvpopupabout);
TextView tvpopupservices = (TextView)popupView.findViewById(R.id.tvpopupservices);
TextView tvpopupcontact = (TextView)popupView.findViewById(R.id.tvpopupcontact);
Typeface typeFace2 = Typeface.createFromAsset(getAssets(),"fonts/arboriaboldregular.ttf");
tvpopupwork.setTypeface(typeFace2);
tvpopupabout.setTypeface(typeFace2);
tvpopupservices.setTypeface(typeFace2);
tvpopupcontact.setTypeface(typeFace2);
tvpopupwork.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Home.this,Ourwork.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
});
tvpopupabout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Home.this,Aboutus.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
});
tvpopupservices.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Home.this,Services.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
});
tvpopupcontact.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Home.this,Contact.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
});
ivmainmenu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
}
});
Сво дает мне результат того, что я хочу, но когда я закрываю из меню не открывается снова, я хочу, чтобы открыть его снова, так что я должен делать? спасибо.
Не работает на Android 4.4.2 –
я должен был установить фон с не нулевой Drawable, по крайней мере, 'popupWindow.setBackgroundDrawable (новый ColorDrawable (Color.TRANSPARENT));' –