gpt4 book ai didi

android - 如何通过单击 imageview Android 从库中加载图像

转载 作者:太空狗 更新时间:2023-10-29 16:32:19 25 4
gpt4 key购买 nike

我的 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 - 如何通过单击 imageview Android 从库中加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35722139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com