- 这是点击popupwindows的点击事件
case R.id.tv_pick_phone:
Toast.makeText(getActivity(), "从手机相册选择", Toast.LENGTH_SHORT).show();
popupWindow.dismiss();
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,1);
break;
- 点击
- 实现代码(选择图片并进行setImageBitmap加载)
@Override
public void onDismiss() {
setBackgroundAlpha(1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//获取图片路径
if (requestCode == CAMERA_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
Uri selectedImage = data.getData();
String[] filePathColumns = {MediaStore.Images.Media.DATA};
String path = getImagePath(selectedImage,null);
Cursor c = getActivity().getContentResolver().query(selectedImage, filePathColumns, null, null, null);
c.moveToFirst();
int index=c.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
String imagePath = c.getString(index);
showImage(imagePath);
//upload(imagePath);上传功能还没实现
c.close();
}
}
//加载图片
private void showImage(String imagePath){
Bitmap bm = BitmapFactory.decodeFile(imagePath);
((ImageView)getActivity().findViewById(R.id.head)).setImageBitmap(bm);
}
private String getImagePath(Uri uri, String seletion) {
String path = null;
Cursor cursor = getActivity().getContentResolver().query(uri, null, seletion, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
}
cursor.close();
}
return path;
}
- 贴上圆形头像代码
public class CircleImageView extends android.support.v7.widget.AppCompatImageView {
private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;
private static final Bitmap.Config BITMAP_CON