In Android how to set image in DialogBox?
I created a dialogBox in my Android application.i want to show with image in that dialog Box.But i Cannot create image.kindly help me. Thanks in Advance here my Coding;
public void createbtnteam_adelaide()
{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setMessage("What kind of Banner do you Want to Create?");
//my new code
ImageView image = (ImageView) alertDialog.findViewById(R.drawable.team_brisbane);
image.setImageResource(R.drawable.team_brisbane);
alertDialog.setButton("Text Only", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.setButton2("Text+Image", new DialogInterface.OnClickListener() {
public void o开发者_运维技巧nClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.show();
}
} i have Small icon in team_gwsid(imageid).
The Android Developer site has an excellent article on how to create dialogs in Android, including custom dialogs. I think you solve your problem by having a look at that, it's pretty easy to do.
Here's the link: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
By the way (not related to this question): I see you've asked six questions here on StackOverflow, and haven't accepted any of them. This is usually what you do when someone helps you to solve your problems.
There ia a alertDialog.setView(View view)
method that enables you to set a custom view.
This does not affect the buttons or the titlebar.
In standard dialog the icon is shown only if you set title too. You have to use setTitle
to see result of setIcon
. Icon is shown in title of the dialog.
You can use Set icon or SetTitle to Display the Images in DialogBox. Read this Tutorial
public void createbtnteam_adelaide()
{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setIcon(R.drawable.team_adelaide);
alertDialog.setTitle("What kind of Banner do you Want to Create?");
alertDialog.setButton("Text Only", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.setButton2("Text+Image", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.show();
}
精彩评论