创建一个sample.xml并在该XML中添加ImageView.
sample.xml中
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/dialog_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
Java代码:
AlertDialog.Builder alertadd = new AlertDialog.Builder(MessageDemo.this);
LayoutInflater factory = LayoutInflater.from(MessageDemo.this);
final View view = factory.inflate(R.layout.sample, null);
alertadd.setView(view);
alertadd.setNeutralButton("Here!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}
});
alertadd.show();