在对话框中显示图像不显示任何内容

时间:2015-12-23 07:13:21

标签: android dialog

在我的应用程序中,我有一个按钮,当取消时应显示一个仅包含图像的对话框。从URL检索图像。但是当点击按钮时,不会显示任何内容。

我的代码

public void onClick(View v){

    final Dialog dialog = new Dialog(SingleItemView.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

    ImageView imgvw = new ImageView(SingleItemView.this);
    String imgurl =descImgOne;
    Uri imguri = Uri.parse(imgurl);
    imgvw.setImageURI(imguri);
    dialog.getWindow().getAttributes().windowAnimations = R.style.SmileWindow;
    dialog.addContentView(imgvw, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
               ViewGroup.LayoutParams.MATCH_PARENT));

     dialog.show();
}

在descImgOne中分配了URL链接

4 个答案:

答案 0 :(得分:1)

    public void onClick(View v){

    final Dialog dialog = new Dialog(SingleItemView.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.customdialog);

    ImageView imageView= (ImageView).dialog.findViewById(R.id.dialogimageview);
    URL url = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464");
    Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
    imageView.setImageBitmap(bmp);

    dialog.show();
}

customdialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/dialogimageview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />


</LinearLayout>

答案 1 :(得分:0)

使用需要使用setContentViewDialog custom layout

dialog.setContentView(R.layout.dialog_layout);

答案 2 :(得分:0)

imgvw.setBackgroundResource(R.drawable.app_launcher);

尝试这个,如果它呈现然后在uri

有一些问题

答案 3 :(得分:0)

其中一个工作代码(使用对话框中的Web视图)

AlertDialog.Builder alert = new AlertDialog.Builder(this);

WebView wv = new WebView(this);
wv.loadUrl("http://www.jjyproductions.com/wp-content/uploads/2014/02/IMG_3454-001.jpg");
wv.setWebViewClient(new WebViewClient() {

   @Override
   public boolean shouldOverrideUrlLoading(WebView view, String url) {

     view.loadUrl(url);
     return true;

   }    
});

   wv.setLayoutParams(new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

   alert.setView(wv);

   alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
  });
  alert.show();