---
title: "Notification "
author: "trygood"
date: "2011-03-25T11:07:56Z"
tags: []
categories: ["移动开发"]
slug: "notification"
draft: false
lastmod: "2011-03-25T11:07:56Z"
id: 974998
url: "https://trygood.iteye.com/blog/974998"
---

Android系统的状态栏（Status Bar）中有一个创新UI设计，这就是可以下拉的通知提示。当系统有一些消息要通知用户时，例如，收到短信、电子邮件、有未接来电时，都会把信息作为通知（Notification）发送给用户。
下面我们来通过一个例子来学习Notification的使用，具体的使用方法同样也会写在代码注释里。
1、新建一个项目Lesson19_Notification，主Activity叫 MainNotification.java
2、拷贝

![](http://dl.iteye.com/upload/attachment/446499/02776d78-7dbf-32a3-bca3-69031c1a4cb4.png)![](http://dl.iteye.com/upload/attachment/446501/fa576e70-79fa-3129-994d-490ac4211cef.png)
![](http://dl.iteye.com/upload/attachment/446503/6a264396-a0e8-3ad5-8ffb-33942c64b0f8.png)
![](http://dl.iteye.com/upload/attachment/446505/3c74bd86-08b9-3728-aabf-822581936c57.png)
![](http://dl.iteye.com/upload/attachment/446507/4cfa138b-76ff-3518-8f73-d87e9d270374.png)

 几张状态图到res/drawable/目录下
3、res/layout/main.xml的内容如下：
1	<textview android:layout_height="wrap_content" android:layout_width="wrap_content"android:id="@+id/mText" android:text="登录状态：" android:textsize="20sp">
2	  <spinner android:layout_height="wrap_content" android:layout_width="wrap_content"android:id="@+id/mySpinner" android:textsize="20sp" android:minwidth="150dp">
3	</spinner></textview>
4、MainNotification.java的内容如下：
01	package android.basic.lesson19;
02
03	import android.app.Activity;
04	import android.os.Bundle;
05	import android.widget.Toast;
06
07	public class StatusActivity extends Activity {
08
09	    @Override
10	    protected void onCreate(Bundle savedInstanceState) {
11	        super.onCreate(savedInstanceState);
12	        Toast.makeText(this, "StatusActivity", Toast.LENGTH_SHORT).show();
13	        finish();
14	    }
15
16	}
6、运行程序，查看一下效果：


![](http://dl.iteye.com/upload/attachment/446509/44446409-a90a-3fa9-900d-4c4842ff0697.png)

![](http://dl.iteye.com/upload/attachment/446511/e29fccad-1ebb-3cc2-8207-3c1dd97fce6c.png)

![](http://dl.iteye.com/upload/attachment/446513/3fa12890-5db6-3d5b-a3eb-49ef9ba76bda.png)

![](http://dl.iteye.com/upload/attachment/446515/7ae952c8-01d2-36df-a00c-c9cf345b0865.png)