您的位置:首页 > 其它

AlertDialog 创建简单的 弹出对话框

2012-11-16 15:14 507 查看
效果图:







一个 java文件,一个 xml布局文件 只有一个button

java文件代码:

public class Main extends Activity {


[code] 


private static final String tag = "==CrazyIt.org==";


 


@Override


public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);


setContentView(R.layout.activity_main);


final Builder b = new AlertDialog.Builder(this);


Button btn = (Button) findViewById(R.id.btn);


btn.setOnClickListener(new OnClickListener() {


 


public void onClick(View v) {


// TODO Auto-generated method stub


b.setIcon(R.drawable.z1);


b.setTitle("标题");


b.setMessage("进入了对话框!");


b.setPositiveButton("确定",


new DialogInterface.OnClickListener() {


public void onClick(DialogInterface dialog,


int which) {


                // TODO Auto-generated method stub


Toast.makeText(Main.this, "点击确定按钮",


Toast.LENGTH_SHORT).show();


}


});


b.setNegativeButton("取消",


new DialogInterface.OnClickListener() {


 


public void onClick(DialogInterface dialog,


int which) {


                // TODO Auto-generated method stub


Toast.makeText(Main.this, "点击取消按钮",


Toast.LENGTH_SHORT).show();


}


});


b.setNeutralButton("aaa",


new DialogInterface.OnClickListener() {


 


public void onClick(DialogInterface dialog,


int which) {


                // TODO Auto-generated method stub


Toast.makeText(Main.this, "点击。。。按钮",


Toast.LENGTH_SHORT).show();


}


});


b.create().show();


}


});


}


 


@Override


public boolean onCreateOptionsMenu(Menu menu) {


getMenuInflater().inflate(R.menu.activity_main, menu);


return true;


}


}

[/code]

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐