/** 下面是选择照片 */ private void choosePic() { try { final PopupWindow pop = new PopupWindow(this); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.popup_pick_photo, null); final LinearLayout ll_popup = (LinearLayout) view.findViewById(R.id.popupLayout); pop.setWidth(LayoutParams.MATCH_PARENT); pop.setHeight(LayoutParams.WRAP_CONTENT); pop.setBackgroundDrawable(new BitmapDrawable()); pop.setFocusable(true); pop.setOutsideTouchable(true); pop.setContentView(view); pop.setOnDismissListener( new PopupWindow.OnDismissListener() { @Override public void onDismiss() { backgroundRecovery(); } }); RelativeLayout rootLayout = (RelativeLayout) view.findViewById(R.id.parentLayout); TextView cameraTextView = (TextView) view.findViewById(R.id.cameraTextView); TextView PhotoTextView = (TextView) view.findViewById(R.id.PhotoTextView); TextView cancelTextView = (TextView) view.findViewById(R.id.cancelTextView); rootLayout.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { pop.dismiss(); ll_popup.clearAnimation(); } }); cameraTextView.setOnClickListener( new OnClickListener() { public void onClick(View v) { pop.dismiss(); ll_popup.clearAnimation(); takePhoto(); } }); PhotoTextView.setOnClickListener( new OnClickListener() { public void onClick(View v) { pop.dismiss(); ll_popup.clearAnimation(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_PICK); intent.setType("image/*"); context.startActivityForResult(intent, FLAG_CHOOSE_IMG); } }); cancelTextView.setOnClickListener( new OnClickListener() { public void onClick(View v) { pop.dismiss(); ll_popup.clearAnimation(); } }); pop.showAtLocation(findViewById(R.id.rootLayout), Gravity.BOTTOM, 0, 0); backgroundDarken(); } catch (Exception e) { e.printStackTrace(); } }