Android API Demos学习 - Notification部分
来源:互联网 发布:linux 查cpu核心数 编辑:程序博客网 时间:2024/06/03 17:37
1. NotifyWithText
第一个显示时间短一些,第二个显示时间长一点。
显示一个Toast,先创建一个视图,然后使用这个视图显示toast。
先获得NotificationManager 对象,然后创建Notification 对象。
status_bar_balloon中定义了一个图片和一个文本:
3.3 Use default values where applicable 介绍使用缺省声音,震动或是两者的方法。
展示了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 介绍使用缺省声音,震动或是两者的方法。
- Android API Demos学习 - Notification部分
- Android API Demos学习 - Activity部分
- Android API Demos学习 - Alarm部分
- Android API Demos学习 - Service部分
- Android API Demos学习 - Dialog部分
- Android API Demos中的Clipping学习笔记
- Android API Demos学习(1) - Hello World
- Android API Demos学习(3) - Persistent State
- Android API Demos学习(4) - Receive Result
- android Api Demos
- Android API Demos笔记
- Android的API Demos
- Android的API Demos
- android API Demos 路径
- Android Api Demos登顶之路(四十九)Notification-->Incoming Message
- Android Api Demos登顶之路(五十)Notification-->Service Controller
- Android Api Demos登顶之路(五十一)Notification-->Status Bar
- API Demos 2.3 学习笔记 (3)-- Android应用程序架构
- Hibernate核心思想—ORM机制(二)
- 第6章 写一个块设备驱动
- IT技术开发人员35岁之前应该做的十件事
- Hibernate核心思想—ORM机制(三)
- Android HAL 开发 (4)
- Android API Demos学习 - Notification部分
- request.getParameter()和request.getAttribute()
- Oracle客户端配置
- JS
- Spring核心(一)概述
- SQL SERVER2008触发器 inserted deleted
- Spring核心(二)IoC介绍
- ORA-0163: 表 a 无法通过 128(在表空间 abc 中) 扩展,表空间不足
- logback 配置生成多个log文件