我的 Activity 中有一个 ImageView ...我想在 ImageView 上放置 TextView (“单击加载图像”)...当用户单击空 ImageView 时想要从那里调用图库部分,他可以选择图片并将其加载到 Imageview
我们怎样才能做到这一点?
最佳答案
试试这个代码....
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Pick Image from")
.setPositiveButton("Camera", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//camera intent
Intent cameraIntent = new Intent(ConversationActivity.this, CameraActivity.class);
cameraIntent.putExtra("EXTRA_CONTACT_JID", contact.getJid());
startActivity(cameraIntent);
}
})
.setNegativeButton("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
});
AlertDialog alert = builder.create();
alert.show();
关于android - 如何通过单击 Android ImageView 从图库加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35722139/