您的位置:首页 > 移动开发 > Android开发

android Notification 图标动态替换

2016-05-27 17:40 337 查看
方法1:

Class<?> clazz = Class.forName("com.android.internal.R$id");  
              
            Field field = clazz.getField("icon");  
            field.setAccessible(true);  
            id_icon = field.getInt(null);  

            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;
     }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: