下面的代码将创建一个简单的警告对话框一个按钮。在下面的代码中使用setTitle()
方法来设置Title to alert对话框。 setMessage()
用于设置消息到警报对话框。 setIcon()
是设置图标提醒对话框
AlertDialog alertDialog = new AlertDialog.Builder(
AlertDialogActivity.this).create();
// Setting Dialog Title
alertDialog.setTitle("Alert Dialog");
// Setting Dialog Message
alertDialog.setMessage("Welcome to AndroidHive.info");
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.tick);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
// Showing Alert Message
alertDialog.show();
事半功倍。 http://developer.android.com/guide/topics/ui/dialogs.html – user370305 2013-02-22 09:33:19
OMG有什么问题? – duggu 2013-02-22 09:41:52
@HCD我也有棘手的问题。你想回答吗? – user2033660 2013-02-22 09:51:32