一:Toast
Toast.makeText(this,"提示消息一",Toast.LENGTH_SHORT).show();
二:Notification
显示在手机状态栏的通知。它代表的是一种全局效果的通知。
//1、得到一个消息管理器
manager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
//消息发送的时机(自定)
//2、创建一个消息对象
Notificationnotification=
newNotification(R.drawable.ic_launcher,"通知1",System.currentTimeMillis());
//5、设置意图对象
Intentintent=newIntent(this,SecondActivity.class);
//4、设置关联的Activity
PendingIntentcontentIntent=PendingIntent.getActivity(this,0,intent,0);
//3、设置消息的主体内容
notification.setLatestEventInfo(this,"标题一","内容一",contentIntent);
notification.flags=Notification.FLAG_AUTO_CANCEL;//点击完自动消失
//notification.flags=Notification.FLAG_ONGOING_EVENT;//点击之后不会消失
//6、通过消息管理器发送一条消息
manager.notify(123,notification);
三:AlertDialog对话框
//1、首先得到一个builder对象
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
//2、通过builder对象设置对话框内容
builder.setTitle("Dialog");//z设置对话框标题
builder.setMessage("消息!");//设置对话框消息内容
//设置对话框按钮,按钮对象只与位置有关
builder.setPositiveButton("确定",newDialogInterface.OnClickListener(){
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
startActivity(newIntent(MainActivity.this,SecondActivity.class));
}
});
builder.setNegativeButton("取消",null);
builder.setNeutralButton("应用",null);
//3、通过builder对象创建一个AlertDialog对象
AlertDialogdialog=builder.create();
//4、把AlertDialog展示出去。
dialog.show();
转载于:https://blog.51cto.com/wsy891008/1307715