문제

How can I show an image when I open an AlertDialog?

Or is there any other way to show an image except ImageView?

I got this code, but it's only showing text and I can't seem to find way to show an image:

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();
        }
    });
}
도움이 되었습니까?

해결책

Build everything you want into a layout of some kind like a LinearLayout, either programmatically or in XML that you inflate at runtime. Then use the AlterDialog.Builder's setView method to assign that layout to the dialog.

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

다른 팁

Use following code

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();
        }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top