【起航计划 026】2015 起航计划 Android APIDemo的魔鬼步伐 25 App->Notification->Status Bar 状态栏显示自定义的通知布局,省却声音、震动
这个例子的Icons Only 和 Icons and marquee 没有什么特别好说明的。
而Use Remote views in balloon 介绍了可以自定义在Extended Status bar显示Notification的Layout,Extended Status Bar缺省显示Notification 是一个图标后接文字,对应大多数情况是够用了。但如果有需要也可以使用自定义的Layout在Extented Status bar显示Notification,方法是通过RemoteView:
private void setMoodView(int moodId, int textId) {
// Instead of the normal constructor, we're going to use the one with no args and fill
// in all of the data ourselves. The normal one uses the default layout for notifications.
// You probably want that in most cases, but if you want to do something custom, you
// can set the contentView field to your own RemoteViews object.
Notification notif = new Notification();
// This is who should be launched if the user selects our notification.
notif.contentIntent = makeMoodIntent(moodId);
// In this sample, we'll use the same text for the ticker and the expanded notification
CharSequence text = getText(textId);
notif.tickerText = text;
// the icon for the status bar
notif.icon = moodId;
// our custom view
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;
// we use a string id because is a unique number. we use it later to cancel the
// notification
mNotificationManager.notify(MOOD_NOTIFICATIONS, notif);
}
为了和缺省的Status Bar Layout有所区别,我们在/res/status_bar_balloon.xml 在增加一个ImageView:左右各显示一个图标,中间为文字。
<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” />
<ImageView android:id=”@+id/icon1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginRight=”10dip” /> </LinearLayout>

Use default values where applicable 介绍使用缺省声音,震动或是两者的方法:
int default = Notification.DEFAULT_SOUND;
//Notification.DEFAULT_SOUND
//Notification.DEFAULT_VIBRATE
//Notification.DEFAULT_ALL notification.defaults = defaults;
注:例子中使用了同样的Notification ID :R.layout.status_bar_notifications ,因此每次调用mNotificationManager.notify 都会更新同一个Notification。
【起航计划 026】2015 起航计划 Android APIDemo的魔鬼步伐 25 App->Notification->Status Bar 状态栏显示自定义的通知布局,省却声音、震动的更多相关文章
- 【起航计划 002】2015 起航计划 Android APIDemo的魔鬼步伐 01
本文链接:[起航计划 002]2015 起航计划 Android APIDemo的魔鬼步伐 01 参考链接:http://blog.csdn.net/column/details/mapdigitap ...
- 【起航计划 037】2015 起航计划 Android APIDemo的魔鬼步伐 36 App->Service->Remote Service Binding AIDL实现不同进程间调用服务接口 kill 进程
本例和下个例子Remote Service Controller 涉及到的文件有RemoteService.java ,IRemoteService.aidl, IRemoteServiceCallb ...
- 【起航计划 031】2015 起航计划 Android APIDemo的魔鬼步伐 30 App->Preferences->Advanced preferences 自定义preference OnPreferenceChangeListener
前篇文章Android ApiDemo示例解析(31):App->Preferences->Launching preferences 中用到了Advanced preferences 中 ...
- 【起航计划 027】2015 起航计划 Android APIDemo的魔鬼步伐 26 App->Preferences->Preferences from XML 偏好设置界面
我们在前面的例子Android ApiDemo示例解析(9):App->Activity->Persistent State 介绍了可以使用Shared Preferences来存储一些状 ...
- 【起航计划 020】2015 起航计划 Android APIDemo的魔鬼步伐 19 App->Dialog Dialog样式
这个例子的主Activity定义在AlertDialogSamples.java 主要用来介绍类AlertDialog的用法,AlertDialog提供的功能是多样的: 显示消息给用户,并可提供一到三 ...
- 【起航计划 012】2015 起航计划 Android APIDemo的魔鬼步伐 11 App->Activity->Save & Restore State onSaveInstanceState onRestoreInstanceState
Save & Restore State与之前的例子Android ApiDemo示例解析(9):App->Activity->Persistent State 实现的UI类似,但 ...
- 【起航计划 003】2015 起航计划 Android APIDemo的魔鬼步伐 02 SimpleAdapter,ListActivity,PackageManager参考
01 API Demos ApiDemos 详细介绍了Android平台主要的 API,android 5.0主要包括下图几个大类,涵盖了数百api示例:
- 【起航计划 033】2015 起航计划 Android APIDemo的魔鬼步伐 32 App->Service->Foreground Service Controller service使用,共享service,前台服务,onStartCommand
Android系统也提供了一种称为“Service”的组件通常在后台运行.Activity 可以用来启动一个Service,Service启动后可以保持在后台一直运行,即使启动它的Activity退出 ...
- 【起航计划 035】2015 起航计划 Android APIDemo的魔鬼步伐 34 App->Service->Local Service Controller
Local Service Controller 是将LocalService当作“Started”Service来使用,相对于”Bound” Service 来说,这种模式用法要简单得多,Local ...
随机推荐
- Windows多个应用程序共享全局变量,静态变量
默认情况下exe不同实例使用copy-on-write技术避免共享数据,比如运行了两个exe,最开始它们使用的都是一份虚拟内存页,然后第一个实例修改了全局变量, 这时候COW就会复制那一页,然后将第一 ...
- 【模板】文艺平衡树(Splay) 区间翻转 BZOJ 3223
您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 4 1 N,M<= ...
- HDU6301 Distinct Values (多校第一场1004) (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 关于nginx限速的配置
limit_req zone=req_one burst=; zone定义了一个req_one的name,burst表示允许超过限制的请求数不多于20个,后面可加参数(nodelay):超过的请求不会 ...
- Redis学习笔记(1)—— NoSQL&Redis简介
一.NoSQL概述 1.1 什么是NoSQL NoSQL(NoSQL = Not Only SQL),意指“不仅仅是SQL”,是一项全新的数据库理念,泛指非关系型的数据库. 1.2 为什么需要NoSQ ...
- [Leetcode]016. 3Sum Closest
public class Solution { public int threeSumClosest(int[] num, int target) { int result = num[0] + nu ...
- Spring Boot如何初始化数据
Hibernate机制:classpath下的import.sql,l在ddl-auto是create和create-drop时自动执行,如果ddl-auto设置为update就不合适,所以此选项不适 ...
- springmvc怎么重定向
转载大神: https://blog.csdn.net/wabiaozia/article/details/50252661
- hdu 6287
选出来比较合适的博客 https://blog.csdn.net/Tony5t4rk/article/details/80490711 https://blog.csdn.net/Game_Acm/a ...
- 6-----selenuim和phantonJs处理网页动态加载数据的爬取
动态数据加载处理 一.图片懒加载 什么是图片懒加载? 案例分析:抓取站长素材http://sc.chinaz.com/中的图片数据 #!/usr/bin/env python # -*- coding ...