main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Spinner android:id="@+id/spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" ></Spinner> </LinearLayout> Manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.itxinke.www" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="7" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".NotifyActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".NotifyActivity_1" android:label="@string/app_name" ></activity> </application> </manifest> NotifyActivity.java package com.itxinke.www; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; public class NotifyActivity extends Activity { /** Called when the activity is first created. */ private Spinner spinner; private ArrayAdapter<String> arrayAdapter; private String[] values = { "在线","离开","忙碌中","马上回来","离线" }; private NotificationManager notificationManager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); spinner = (Spinner)findViewById(R.id.spinner); notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,values); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(arrayAdapter); spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub if(values[arg2].equals("在线")) { setNotify(R.drawable.msn,values[0]); } else if(values[arg2].equals("离开")) { setNotify(R.drawable.away,values[1]); } else if(values[arg2].equals("忙碌中")) { setNotify(R.drawable.busy,values[2]); } else if(values[arg2].equals("马上回来")) { setNotify(R.drawable.min,values[3]); } else if(values[arg2].equals("离线")) { setNotify(R.drawable.offine,values[4]); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); } //其中iconId 和 text都会显示在状态栏上。 //通知区域显示的为:notify.icon notify.tickerText private void setNotify(int iconId,String text) { Intent intent = new Intent(NotifyActivity.this, NotifyActivity_1.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Notification notify = new Notification(); PendingIntent pendingIntent = PendingIntent.getActivity(NotifyActivity.this,0,intent,0); notify.icon = iconId; notify.tickerText = text; //注意 此时 若这样定义则出现异常 notfy.defaults = Notification.DEFAULT_ALL; notify.defaults = Notification.DEFAULT_SOUND; //登录状态为标题,msn为内容 notify.setLatestEventInfo(NotifyActivity.this,"登录状态","msn",pendingIntent); notificationManager.notify(0,notify); } }