【问题标题】:Add custom image to Dialog将自定义图像添加到对话框
【发布时间】:2013-05-09 19:40:18
【问题描述】:

我试图做的是一个读取 QR-CODE(指图像)的应用程序,并在读取之后显示一个对话框,其中包含与 QR-CODE 相关的图像和数据库获取的描述。

关于如何做到这一点的任何建议?

我可以在 Internet 上找到的只是如何使用自定义布局创建对话框。仅此而已。

【问题讨论】:

  • 你在找什么,如何制作自定义对话框..是你的问题
  • 您需要在自定义对话框中显示自定义图像吗?
  • @Raghunandan 是的,就是这样。你知道怎么做吗?
  • 好吧,如果只需要带有图像的自定义对话框,那么go for this link。希望。这有帮助。如果不是这样,请明确说明您想要什么。

标签: android dialog android-imageview qr-code


【解决方案1】:

我假设您需要在自定义对话框中显示图像

定义对话框.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />

</RelativeLayout>

在您点击按钮的活动中显示一个对话框

 Button b= (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            showpopup();        
        }

    });

   public void showpopup()
   {
   Dialog d = new Dialog(MainActivity.this);
   d.setContentView( R.layout.dialog);
   d.setTitle("my title");
   ImageView iv = (ImageView) d.findViewById(R.id.imageView1);
   iv.setImageResource(R.drawable.afor); 
   // set your image here. I have used a resource from the drawable folder
   d.show();
   }

【讨论】:

  • 非常感谢@Raghunandan。你马上就解决了我的问题,现在我可以做我想做的事了!现在我正在尝试从数据库中获取描述
  • @StefanoMunarini 很高兴它有帮助
  • 是的,抱歉,这是一次错误点击。你说对了!非常感谢
  • 我想如果图像是 A for android 会更好看:P
  • 你能帮帮我吗?我注意到这样做,它只是让我选择 R.drawable.afor 。但我每次都必须选择不同的图像,而不是总是“afor”
【解决方案2】:

您可以使用setContentView() n 只需将 ImageView 作为参数传递给它。

【讨论】:

  • 我想添加自定义图片。
【解决方案3】:

对于自定义对话框,您只需创建一个布局并在对话框中设置该布局。

例如

dialog.setContentView(R.layout.customdialog);

看这个例子,Click Here.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    • 2019-07-04
    • 2011-07-06
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 2022-10-14
    相关资源
    最近更新 更多