1. NotifyWithText 展示了Toast的使用方法:
 Toast.makeText(NotifyWithText.this, R.string.short_notification_text,                    Toast.LENGTH_SHORT).show();Toast.makeText(NotifyWithText.this, R.string.long_notification_text,                    Toast.LENGTH_LONG).show();

第一个显示时间短一些,第二个显示时间长一点。
2. IncomingMessage 展示了怎么发送一个持久和短暂的提醒,并且用xml定义提醒的样式。
protected void showToast() {        View view = inflateView(R.layout.incoming_message_panel);        TextView tv = (TextView)view.findViewById(R.id.message);        tv.setText("khtx. meet u for dinner. cul8r");        Toast toast = new Toast(this);        toast.setView(view);        toast.setDuration(Toast.LENGTH_LONG);        toast.show();    }

显示一个Toast,先创建一个视图,然后使用这个视图显示toast。
protected void showNotification() {        NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);        CharSequence from = "Joe";        CharSequence message = "kthx. meet u for dinner. cul8r";        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,                new Intent(this, IncomingMessageView.class), 0);        String tickerText = getString(R.string.imcoming_message_ticker_text, message);        Notification notif = new Notification(R.drawable.stat_sample, tickerText,                System.currentTimeMillis());        notif.setLatestEventInfo(this, from, message, contentIntent);        notif.vibrate = new long[] { 100, 250, 100, 500};        nm.notify(R.string.imcoming_message_ticker_text, notif);    }

先获得NotificationManager对象,然后创建Notification对象。 setLatestEventInfo设置通知的标题,内容,Intent信息。 vibrate是震动信息,第一个100表示100毫秒后开始震动,250表示震动的时间,第三个和第一个一样,第四个和第二个一样,依次类推。 notify的第一个参数是这个提示信息的ID。可以使用它来开始一个提示或者关闭一个提示。比如在IncomingMessageView.java中:
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);nm.cancel(R.string.imcoming_message_ticker_text);


3. Status Bar 3.1 Icons only和 Icons and marquee一个是自显示图标,一个是显示图标和文字。 3.2 Use Remote views in balloon 介绍了可以自定义显示Notification的contentView。
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.status_bar_balloon);contentView.setTextViewText(R.id.text, text);contentView.setImageViewResource(R.id.icon, moodId);notif.contentView = contentView;

status_bar_balloon中定义了一个图片和一个文本:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"    android:baselineAligned="false"    android:gravity="center_vertical"    android:layout_width="wrap_content"    android:layout_height="wrap_content">   <ImageView android:id="@+id/icon"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginRight="10dip" />    <TextView android:id="@+id/text"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textColor="#ffffffff" />    </LinearLayout>

3.3 Use default values where applicable 介绍使用缺省声音,震动或是两者的方法。

更多相关文章

  1. android中文api(89)——ViewManager
  2. Android中的FILL_PARENT与WRAP_CONTENT的区别
  3. Android(安卓)P SystemUI之StatusBar UI布局status_bar.xml解析
  4. android用户界面-组件Widget-地图视图MapView
  5. Android(安卓)中文API(86)——ResourceCursorAdapter
  6. android用户界面-组件Widget-画廊视图Gallery
  7. android 中文api (62) —— ViewSwitcher.ViewFactory
  8. Android中使Dialog显示时背景不变暗
  9. Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明

随机推荐

  1. Android(安卓)8.0 新特性
  2. Android(安卓)滑动侧边栏(Sliding Menu)第
  3. Android(安卓)boot.img介绍
  4. 25、Android中通过Intent传递对象、集合
  5. android的测试工具CTS
  6. 用git下载Android的某个应用程序
  7. android保存文件到手机内存
  8. Android(安卓)N中UI硬件渲染(hwui)的HWUI_N
  9. 如何快速启动安卓模拟器(Android(安卓)Em
  10. Android(安卓)ListView 去除边缘阴影、选