android Notification 图标动态替换

来源:互联网 发布:一战游戏知乎 编辑:程序博客网 时间:2024/06/11 09:59

方法1:

  1. Class<?> clazz = Class.forName("com.android.internal.R$id");  
  2.               
  3.             Field field = clazz.getField("icon");  
  4.             field.setAccessible(true);  
  5.             id_icon = field.getInt(null);  
  1.             n.contentView.setImageViewBitmap(InternalID.id_icon, icon);  

参考:http://blog.csdn.net/z1074971432/article/details/10446715


方法2:

关于Notification 图标动态替换问题 ,当然如果使用自定义的方式可以直接替换,如果使用系统的方式怎样替换了,废话不多代码如下
View localView = LayoutInflater.from(this.getApplicationContext()).inflate(taskNotify.contentView.getLayoutId(), null);
         if (localView != null);
          ImageView localImageView =GetImaeView(localView);
         if ((localImageView != null) && (bitmap != null));
         taskNotify.contentView.setImageViewBitmap(localImageView.getId(), bitmap);
//查找ImageView
protected static ImageView GetImaeView(View paramView)
     {
       if (paramView instanceof ImageView)
         return (ImageView)paramView;
       if (paramView instanceof ViewGroup)
         for (int i = 0; i < ((ViewGroup)paramView).getChildCount(); ++i)
         {
           View localView = ((ViewGroup)paramView).getChildAt(i);
           if (localView instanceof ImageView)
             return (ImageView)localView;
           if (localView instanceof ViewGroup)
             return GetImaeView(localView);
         }
       return null;
     }





0 0
原创粉丝点击