怎么让Notification添加的状态图标上加上数字,像安卓市场提示有几个应用要升级一样 本帖最后由 linbill168 于 2012-01-23 13:52:13 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我自己试过一个方法,用layerDrawable<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item id="@+id/layerBit2"> <bitmap android:src="@drawable/notify" android:gravity="center" /> </item> </layer-list>Notification notify = new Notification();//为Notification设置图标,该图标显示在状态栏 ,图标是必须要设置的LayerDrawable layerDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.layerbit);//通过层次图形上的id设置某一项的图形layerDrawable.setDrawableByLayerId(R.id.layerBit2, getResources().getDrawable(R.drawable.icon));notify.icon = R.drawable.layerbit;但我修改不了layerDrawable中的item 他是把drawable转换成bitmap,再把检测到的数字画上去的。 2楼的兄弟,能否具体给出个例子,现在我的关键问题是不知道怎么把生成好的带数字的bitmap显示到状态栏上去。 Notification.icon只能引用ID来显示,一直找不到方法 我记得傲慢的上校博客上有篇文章是写在联系人的图标上写上一个数字,代表有多少个联系人的例子。另外我觉得也可以写一个xml,然后通过相对布局,把一个textview盖在imageview的右下角,我有个小程序就是这么干的,不过有时候相对布局在ide上的视图显示有bug,只有运行了才知道位置对不对 我记得Notification有个设置xml作为视图的方法。不一定非得icon 代码大致如下private void showNotification() { Notification notification = new Notification(R.drawable.ic_launcher, "驱蚊神手正在运行", System.currentTimeMillis() + 2000); notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; notification.contentView = makeRemoteView(); Intent notificationIntent = new Intent(this, StartActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.icon = R.drawable.wenziicon; notification.contentIntent = contentIntent; manager.notify(1, notification); } private RemoteViews makeRemoteView() { RemoteViews mRemoteViews = new RemoteViews(getPackageName(), R.layout.notification); return mRemoteViews; } 你说的那个帖子是显示联系人的那个吧,他用的就是RemoteViews,这个我试试了不行才来问的,他显示的图片是在状态栏下拉的面板中,不是在状态栏上的,也就是RemoteViews这个是代替状态栏面板中显示信息用的。不过我也不知道是不是全是这样,但我用过的结果是这样的,我搞安卓开发是第一次 求指点:四大组件之一contentprovider,好难理解,怎么办? android 中View onTouchEvent 事件 android字体如何自适应各种分辨率 log信息输出问题 程序太大求教高手。 如何获取控件的宽度 怎么读取字符串的每一行? 打包的问题 用android studio将html5封装成apk abortBroadcast 起作用.我的优先级已经设置1000 为什么还是不能拦截 短信呢 刚入门,请教一个功能的实现 Android中eject出光盘sr0
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item id="@+id/layerBit2">
<bitmap android:src="@drawable/notify" android:gravity="center" />
</item>
</layer-list>Notification notify = new Notification();
//为Notification设置图标,该图标显示在状态栏 ,图标是必须要设置的
LayerDrawable layerDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.layerbit);
//通过层次图形上的id设置某一项的图形
layerDrawable.setDrawableByLayerId(R.id.layerBit2, getResources().getDrawable(R.drawable.icon));
notify.icon = R.drawable.layerbit;但我修改不了layerDrawable中的item
private void showNotification() {
Notification notification = new Notification(R.drawable.ic_launcher,
"驱蚊神手正在运行", System.currentTimeMillis() + 2000);
notification.flags = Notification.FLAG_NO_CLEAR
| Notification.FLAG_ONGOING_EVENT; notification.contentView = makeRemoteView(); Intent notificationIntent = new Intent(this, StartActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.icon = R.drawable.wenziicon;
notification.contentIntent = contentIntent;
manager.notify(1, notification);
} private RemoteViews makeRemoteView() {
RemoteViews mRemoteViews = new RemoteViews(getPackageName(),
R.layout.notification);
return mRemoteViews;
}