驳回后退按钮的弹出窗口 [英] dismiss the popup window by back button

查看:579
本文介绍了驳回后退按钮的弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过点击弹出窗口外或后退按钮以关闭弹出窗口,但是当点击后退按钮我申请退出的,而不是退出我想关闭弹出窗口的应用程序。

I want to Dismiss the popup window by clicking outside of the popup window or by the back button, but when click on the back button my application exit's, instead of exiting the application I want to close the popup window.

这是我的code,

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();
                }
           }
        });

它给了我什么,我想要的结果,但是当我关闭菜单中就不会再次打开时,我想再次打开它,我该怎么办? 谢谢你。

Its gives me the result what I want but when I closes the menu the it does not opens again, I want to open it again so what should I do? thank you.

推荐答案

替换

popupWindow.setOutsideTouchable(false);

popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);

这篇关于驳回后退按钮的弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆