2014-03-27 425 views
0

當我打開AlertDialog時,如何顯示圖像?在AlertDialog中顯示圖片?

或者還有其他方式可以顯示圖像,但ImageView

我得到這個代碼,但它只是顯示的文字和我似乎無法找到方法來顯示圖像:

private void AlertDialogz() { 
    // TODO Auto-generated method stub 
    AlertDialog.Builder alert = new AlertDialog.Builder(context); 
    alert.setTitle("Note"); 
    alert.setMessage(context.getString(R.string.lyrics)); 
    alert.setCancelable(false); 
    alert.setPositiveButton("Zatvori", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int whichButton) { 
      dialog.dismiss(); 
     } 
    }); 
} 
+1

http://stackoverflow.com/a/18504788/1066839 – John

+1

http://stackoverflow.com/questions/6276501/how-to-put-an- image-in-an-alertdialog-android –

回答

0

建立你想變成某種類似的LinearLayout的佈局的一切,無論是以編程方式或在運行時膨脹的XML。 然後使用AlterDialog.Builder的setView方法將該佈局分配給對話框。

LinearLayout imageLayout; 
imageLayout.addView(myImageView, new LinearLayout.LayoutParams()); 
dialog.setView(imageLayout); 
+0

是的,我發現在上面的鏈接。不管怎樣,謝謝 –

0

使用下面的代碼

new AlertDialog.Builder(this) 
    .setIcon(android.R.drawable.ic_dialog_alert) 
     alert.setTitle("Note"); 
     alert.setMessage(context.getString(R.string.lyrics)); 
     alert.setCancelable(false); 
     alert.setPositiveButton("Zatvori", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int whichButton) { 
      dialog.dismiss(); 
     } 
});