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

标签 android layout android-imageview textview

我的 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/

相关文章:

java - Android 可滚动 AlertDialog 以编程方式

android - 在 ListView 中显示来自 URL 的图像

android - 从 Eclipse 运行 Android Activity 单元测试的问题

javascript - 仅允许在 Android 应用程序上访问文件并使用 .htaccess 或 javascript 禁用浏览器访问..?

android - 将 selectableItemBackground 与 ConstraintLayout 结合使用

java - 如何获取 JFrame 中特定布局位置的组件

java - Java Android 中哪个数据库?

javascript - 在调整窗口大小时调整相对于中心的滚动位置?

android - 自定义 ImageView 在 Nexus 7 上自动调整大小

Android为图像添加半透明叠加层