package com.example.dialog;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.support.v4.app.NavUtils;
public class MainActivity extends Activity {
private Button btn=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
btn.setOnClickListener(listener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private void init(){
btn=(Button) findViewById(R.id.btn);
}
private OnClickListener listener=new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView imageView=new ImageView(MainActivity.this);
imageView.setImageResource(R.drawable.ic_launcher);
AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
//显示对话框上面的图片,
dialog.setView(imageView);
dialog.setTitle("对话框显示!");
//为对话框设置要显示的信息
dialog.setMessage("对话框中显示的内容!");
//对话框图标
dialog.setIcon(R.drawable.ic_launcher);
//显示对话框
dialog.show();
}};
}
效果图: