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;
}
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;
}
相关文章推荐
- Android利用Animation.RELATIVE_TO_SELF做出个性化的动画
- Android之ListActivity(一):布局与数据绑定
- arraylist 排序
- Android线程与线程池
- 七牛---Android SDK常见问题总结
- Android控件ImageSwitcher实现左右图片切换功能
- Android坐标系详解
- Android Studio快捷键Ctrl + Alt + Left 或Right不起作用
- 详解Android中AsyncTask的使用
- Android Fragment和FragmentActivity区别和用法
- LoadRunner+Android模所器录制脚本
- LoadRunner+Android模所器录制脚本
- android 进程防止被杀死
- Android客户端性能优化
- Android异步任务处理之AsyncTaskLoader的使用
- Android基础之AsyncTask详解,巨细哟
- Android适配参考
- Android使用WindowManager构造悬浮view
- Androin学习笔记五十八:android触控,先了解MotionEvent
- Android几个bitmap相关的方法