Android通知系統

一: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();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章