解决方案 »

  1.   

    private class PopupWindows extends PopupWindow { @SuppressWarnings("deprecation")
    @TargetApi(Build.VERSION_CODES.CUPCAKE)
    @SuppressLint("NewApi")
    public PopupWindows(Context mContext, View parent) { super(mContext); View view = View.inflate(mContext,
    R.layout.zhgl_userinfo_avatarupdate, null);
    view.startAnimation(AnimationUtils.loadAnimation(mContext,
    R.anim.fade_ins));
    LinearLayout ll_popup = (LinearLayout) view
    .findViewById(R.id.ll_popup);
    ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext,
    R.anim.push_bottom_in_2)); setWidth(LayoutParams.FILL_PARENT);
    setHeight(LayoutParams.FILL_PARENT);
    setBackgroundDrawable(new BitmapDrawable());
    setFocusable(true);
    setOutsideTouchable(true);
    setContentView(view);
    showAtLocation(parent, Gravity.BOTTOM, 0, 0);
    update(); Button bt1 = (Button) view
    .findViewById(R.id.item_popupwindows_camera);
    Button bt2 = (Button) view
    .findViewById(R.id.item_popupwindows_Photo);
    Button bt3 = (Button) view
    .findViewById(R.id.item_popupwindows_cancel);
    bt1.setOnClickListener(new OnClickListener() {
    // 通过相机获得图片
    public void onClick(View v) {
    Intent intentFromCapture = new Intent(
    MediaStore.ACTION_IMAGE_CAPTURE);
    intentFromCapture.putExtra(
    MediaStore.EXTRA_OUTPUT,
    Uri.fromFile(new File(Environment
    .getExternalStorageDirectory(), "head2.png"))); // intentFromCapture.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,
    // 1);
    startActivityForResult(intentFromCapture,
    CAMERA_REQUEST_CODE);
    dismiss();
    }
    });
    bt2.setOnClickListener(new OnClickListener() {
    // 从本地选取图片
    public void onClick(View v) {
    Intent intentFromGallery = new Intent();
    intentFromGallery.setType("image/*"); // 设置文件类型
    intentFromGallery.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(intentFromGallery,
    IMAGE_REQUEST_CODE);
    dismiss();
    }
    });
    bt3.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
    dismiss();
    }
    }); }
    }
    然后在activity里 new PopupWindows(UserInfoActivity.this, aiv);