notification 动态修改扩展后的图标
notification 修改打开之后的图片,最好的办法是使用contentView然后调用布局,然而有时候却要面临不能使用布局的情况也就是你不能使用R.layout。xx,这个样子你就不能动态修改icon的图标了。
?
换一个思路就是调用系统的布局 获得系统显示图片的View 然后重新设置他的图片就可以了
?
private boolean recurseGroup(ViewGroup gp)
{
? ?final int count = gp.getChildCount();
? ?
? ?for (int i = 0; i < count; ++i)
? ?{
? ? ? ?if (gp.getChildAt(i) instanceof ImageView)
? ? ? ?{ ??
? ? ? ?Bitmap mIcon=BitmapFactory.decodeResource(getResources(), R.drawable.icon);
? ? ? ?notification.contentView.setImageViewBitmap(((ImageView) gp.getChildAt(i)).getId(), mIcon);
? ? ??
? ? ? ?mNotification.notify(ID, notification);
? ? ? ? ? ?return true; ? ? ? ? ? ?
? ? ? ?}else if (gp.getChildAt(i) instanceof ViewGroup)
? ? ? ? ? ?return recurseGroup((ViewGroup) gp.getChildAt(i));
? ?}
? ?return false;
}
这里是方法 ?注意我这里为了测试 mIcon还是调用了系统图标,而在我的项目中是不能使用资源文件的,这里尽是测试。
调用
?
notification.setLatestEventInfo(this, "消息", "Hello Android", pi);
LinearLayout group = new LinearLayout(this);
? ? ? ? ViewGroup event = (ViewGroup) notification.contentView.apply(this, group);
? ? ? ? recurseGroup(event);