添加退出按钮

来源:互联网 发布:信鸽种鸽出售淘宝网 编辑:程序博客网 时间:2024/05/16 05:23

添加退出按钮

    private static boolean isExitDlgFlag = false;    private static Handler mExitToMenuHandler = null;    private static void showOverlay() {        mExitToMenuHandler.sendEmptyMessage(1);    }    private static void hidOverlay() {        mExitToMenuHandler.sendEmptyMessage(0);    }    public static void addOverlayViewOnCreate(final Context ctx) {        RelativeLayout.LayoutParams vParames = null;        RelativeLayout bglay = new RelativeLayout(ctx);        vParames = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,                ViewGroup.LayoutParams.WRAP_CONTENT);        vParames.setMargins(0, 0, 0, 0);        vParames.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);        vParames.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);        final ImageButton exitMenuBtn = new ImageButton(ctx);        exitMenuBtn.setBackgroundResource(R.drawable.exit_button);        exitMenuBtn.setOnClickListener(new View.OnClickListener() {            public void onClick(View view) {                //To change body of implemented methods use File | Settings | File Templates.                System.exit(0);            }        });        bglay.addView(exitMenuBtn, vParames);        ((Activity) ctx).addContentView(bglay, vParames);        mExitToMenuHandler = new Handler() {            @Override            public void handleMessage(Message msg) {                super.handleMessage(msg);    //To change body of overridden methods use File | Settings | File Templates.                switch (msg.what) {                    case 0: {                        exitMenuBtn.setVisibility(View.GONE);                        break;                    }                    case 1: {                        if (mGamePlayingFlag) {                            exitMenuBtn.setVisibility(View.VISIBLE);                        }                        break;                    }                    default: {                        break;                    }                }            }        };        hidOverlay();    }



原创粉丝点击