Toast和Notification

Toast和Notification
    针对于Dialog来说是更友好,轻量级的机制来提醒用户。不会打断用户
1 Notification
  通过这种方式你可以使系统:将一个图标在状态条上闪,让机器震动,发出声音等。
2 Toast
这是一个无模式的小窗体,会将显示的信息显示在首页面中:


创建和配置新的Notification需要经历三步
(1)创建一个新的Notification对象  //图标、文字和Notification的当前时间
(2)使用setLatestEventInfo方法来配置Notification在扩展的状态窗口中的外观。
   setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
    context:指显示在哪里(如果是本Activity使用this);
        contentTitle:指展开本Notification后显示的标题
        contentText:指展开本Notification后显示的内容
 contentIntent:指The intent to execute when the expanded status entry is clicked
  
   获取一个PendingIntent:PendingIntent.getActivity(Context context, int requestCode, Intent intent, int flags)

(3)触发一个Notification
 int notificationRef = 1;
 notificationManager.notify(notificationRef, notification);

//其中notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

 protected void showNotification() {
  Notification nt=new Notification(R.drawable.icon,"标题",System.currentTimeMillis());
  PendingIntent pin=PendingIntent.getActivity(this,0,new Intent(),0);
  nt.setLatestEventInfo(this, "展开后的标题", "展开后的内容", pin);
  manager.notify(1, nt);
 }
-------------------------------------------------------------------------------------------------------------------------
2 toast
  new Toast(Context);
  setView(View);
  setDuration(); //Toast.LENGTH_LONG;Toast.LENGTH_SHORT
  show()  //方法

3 设置权限:在AndroidManifest.xml里设置权限:
  <uses-permission android:name="android.permission.VIBRATE" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值