废话不多说,直接上代码了!!
activity
private SimpleDraweeView mine_zi_liao_userPhoto;
private TextView mine_zi_liao_mobile;
private TextView mine_zi_liao_username;
private PopupWindow mPopupWindowDialog;
private Button btn_take_photo;
private Button btn_pick_photo;
private Button btn_cancel;
private static final int PHOTO_REQUEST_CAREMA = 1;// 拍照
private static final int PHOTO_REQUEST_GALLERY = 2;// 从相册中选择
private static final int PHOTO_REQUEST_CUT = 3;// 结果
//点击弹出 popwindow 弹框
public void mine_zi_liao_userPhotos(View view) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vi = inflater.inflate(R.layout.userphotopopwindow, null);
btn_take_photo = (Button) vi.findViewById(R.id.btn_take_photo);
btn_pick_photo = (Button) vi.findViewById(R.id.btn_pick_photo);
btn_cancel = (Button) vi.findViewById(R.id.btn_cancel);
btn_take_photo.setOnClickListener(this);
btn_pick_photo.setOnClickListener(this);
btn_cancel.setOnClickListener(this);
/*pop 设置*/
mPopupWindowDialog = new PopupWindow(vi, ActionBar.LayoutParams.FILL_PARENT, ActionBar.LayoutParams.WRAP_CONTENT);
mPopupWindowDialog.setFocusable(true);
mPopupWindowDialog.update();
mPopupWindowDialog.setBackgroundDrawable(new BitmapDrawable());
mPopupWindowDialog.setOutsideTouchable(true);
/*显示 pop 弹框*/
mPopupWindowDialog.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
}
}
/*选择弹框选项*/
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_take_photo:// 拍照
// 激活相机
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
// 判断存储卡是否可以用,可用进行存储
if (hasSdcard()) {
tempFile = new File(Environment.getExternalStorageDirectory(), "temp_photo.jpg");
// 从文件中创建uri
Uri uri = Uri.fromFile(tempFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
}
// 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_CAREMA
startActivityForResult(intent, PHOTO_REQUEST_CAREMA);
if (mPopupWindowDialog != null && mPopupWindowDialog.isShowing()) {
mPopupWindowDialog.dismiss();
}
break;
case R.id.btn_pick_photo:// 相册
// 激活系统图库,选择一张图片
Intent intent1 = new Intent(Intent.ACTION_PICK);
intent1.setType("image/*");
// 开启一个带有返回值的Activity,请求码为PHOTO_REQUEST_GALLERY
startActivityForResult(intent1, PHOTO_REQUEST_GALLERY);