所以我需要有一个基于我SDCARD上的Image的图标,但是我只能得到Drawable / Bitmap,我怎样才能获得基于它的int资源?
public static String SDCARD_PATH = Environment.getExternalStorageDirectory().getPath() + "/folder/";
public static Drawable getDrawableFromChannelID(int id) {
return Drawable.createFromPath(Utils.SDCARD_PATH + id + ".png");
}
public static Bitmap getBitmapFromChannelID(int id) {
return BitmapFactory.decodeFile(Utils.SDCARD_PATH + id + ".png");
}
答案 0 :(得分:1)
我想你不能。所有R.id ..等都是资源included in your apk。为什么还需要资源ID?
答案 1 :(得分:1)
ImageView icon=new ImageView(this);
img.setBackground(<urDrawableIcon>);
RelativeLayout.LayoutParams iconlayout=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
icon.setId(11111);//set your own id;
icon.setVisibility(View.GONE);
addContentView(icon,iconlayout);
//so your id is 11111; NotificationBuilder.setIcon(11111);