AlertDialog和PopWindow

来源:互联网 发布:windows找不到regedit 编辑:程序博客网 时间:2024/04/29 07:29

AlertDialog

        final String items[] = {AppProfile.getContext().getResources().getString(R.string.tcanclecollect),AppProfile.getContext().getResources().getString(R.string.fcanclecollect)};        //context必须为activity,不能是application        AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.MyDialogTheme);        builder.setTitle(R.string.sure_cancel);        builder.setItems(items, new DialogInterface.OnClickListener() {            @Override            public void onClick(DialogInterface dialog, int which) {                dialog.dismiss();                switch (which) {                    case 0:                        cancelCollect(mLostListItemBean.getId());                        break;                }            }        });            builder.create().show();

PopWindow

View contentView = LayoutInflater.from(this)                .inflate(R.layout.popup_name_edit, null);        RelativeLayout rl_dialog = (RelativeLayout) contentView                .findViewById(R.id.dialog);        final EditText mEtName = (EditText) contentView                .findViewById(R.id.edit_name);        Button btn_confirm = (Button) contentView                .findViewById(R.id.btn_confirm);        Button btn_cancel = (Button) contentView.findViewById(R.id.btn_cancel);        getDisplayMetrics();        final PopupWindow mPopup = new PopupWindow(contentView,                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, true);        // final PopupWindow mPopup = new PopupWindow(SettingActivity.this);        // mPopup.setContentView(contentView);        // mPopup.setWidth(LayoutParams.MATCH_PARENT);        // mPopup.setHeight(LayoutParams.MATCH_PARENT);        rl_dialog.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                // TODO Auto-generated method stub                if (mPopup.isShowing()) {                    mPopup.dismiss();                }            }        });        btn_confirm.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                // TODO Auto-generated method stub                String nickname = mEtName.getText().toString().trim();                if (nickname.equals("")) {                    showToast("昵称不能为空");                    return;                }                if (mPopup.isShowing()) {                    mPopup.dismiss();                }                WebRequest(nickname);            }        });        btn_cancel.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                // TODO Auto-generated method stub                if (mPopup.isShowing()) {                    mPopup.dismiss();                }            }        });        mPopup.setTouchable(true);        mPopup.setFocusable(true);        mPopup.setOutsideTouchable(true);        mPopup.setBackgroundDrawable(new BitmapDrawable());        // 设置动画        mPopup.setAnimationStyle(R.style.PopupAnimationCard);        mPopup.showAtLocation(mRelayout, Gravity.CENTER, 0, 0);
0 0
原创粉丝点击