//import android.app.ActionBar.LayoutParams;
image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View view = View.inflate(MainActivity.this, R.layout.pop, null); //向下往上弹 // popupWindow = new PopupWindow(); // popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); // popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); // popupWindow.setContentView(view); // popupWindow.setOutsideTouchable(true); // popupWindow.setFocusable(true); // popupWindow.setTouchable(true); // popupWindow.setBackgroundDrawable(new ColorDrawable(0xb0000000)); // popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0); PopupWindow popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true); popupWindow.setBackgroundDrawable((new ColorDrawable(0xb0000000))); popupWindow.setOutsideTouchable(true); popupWindow.showAsDropDown(v); but1 = (Button)view. findViewById(R.id.but1); but2 = (Button)view. findViewById(R.id.but2); but1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 123); } }); but2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent, 1234); } }); } });
//获取图片
public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case 123: Parcelable parcelableExtra = data.getParcelableExtra("data"); image.setImageBitmap((Bitmap) parcelableExtra); break; case 1234: Uri uri = data.getData(); image.setImageURI(uri); break; default: break; } }