android系统的技术基础,安卓基础知识之通知系统

Toast、Notification、Dialog

一、Toast

Toast.makeText(this, "提示消息一", Toast.LENGTH_SHORT).show();

第三个参数:显示的时间 Toast.LENGTH_SHORT

Toast.LENGTH_LONG

特性:1、Toast提示不会获取焦点

2、Toast提示消息过一段时间会自己消失。

应用场景:提示用户当前状态,不需要用户确认、反馈。在其他页面仍然可以看到结果。

二、Notification

Notification

显示在手机状态栏的通知。它代表的是一种全局效果的通知。

//1、得到一个消息管理器

manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

//消息发送的时机(自定)

//2、创建一个消息对象

Notification notification =

new Notification(R.drawable.ic_launcher, "通知1", System.currentTimeMillis());

//5、设置意图对象

Intent intent = new Intent(this, SecondActivity.class);

//4、设置关联的Activity

PendingIntent contentIntent = 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 );

//销毁消息

manager.cancel(123);

Notification:

作用:来消息的时候,在通知栏上面显示(时效性不强的消息),当用户点击这个消息的时候

跳转到详细页面查看详细消息。

常见:短信

广告

注:在4.1之后新的方法:Notification.Builder(context)

三、Dialog

//1、首先得到一个builder对象

AlertDialog.Builder builder = new AlertDialog.Builder(this);

//2、通过builder对象设置对话框内容

builder.setTitle("Dialog");//z设置对话框标题

builder.setMessage("消息!");//设置对话框消息内容

//设置对话框按钮,按钮对象只与位置有关

builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

startActivity(new Intent(MainActivity.this, SecondActivity.class));

}

});

builder.setNegativeButton("取消", null);

builder.setNeutralButton("应用", null);

//3、通过builder对象创建一个AlertDialog对象

AlertDialog dialog = builder.create();

//4、把AlertDialog展示出去。

dialog.show();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值